Python with virtualenv

isnochys(67)
Published in
#dev
Words
255
Reading
2 min
Listen
Play
9y


themarkymark@themarkymark made a good tutorial on setting up Steem-Python for Windows.
He only forgot to mention one little thing:

Virtualenv

What is it

Imagine, you have multiple python apps on your server. Some need version 1 of library FooBar, some need version 2 of it.
How could you install 2 different versions of one library on the same machine?
Or another scenario, you don't want to install it as root.
You are just a normal user, without root/admin privileges and need to install that library.
Virtualenv steps in here.
You basically create a new path for your application, where python and all libraries will be installed.

How to install it

This section covers Python Version 3.3+.
Go into your directory, where your application will be.
On Linux enter:
python3 -m venv ENV_DIR
On Windows enter:
C:\Python36\python.exe -m venv ENV_DIR

python3 and C:\Python36\python.exe are your Python executables. This differs from Python version to Python version.

ENV_DIR is a non existing folder, that will be created, I usually use env as name, but this is up to you.

How to use it

Go to your application folder.
On Linux:
$ source env/bin/activate
On Windows:
$ env\Scripts\activate
And your command line will now look like that:
(env)$

Now you can pip install all the things you want.
Oh, and you exit this environment like that:
(env)$ deactivate

You want to get rid of that environment?
$ rm -rf env
On Windows, you just delete the env folder

If you like that tutorial, you can vote for me as witness!

Did you know, that you can make some profit with your witness vote?

Also sorry for the blatant image copy;)

Python with virtualenv | Ecency