Creating Python Virtual Environment Without Installing To The System
When you develop projects in python, you often met the situation where you will need to install various packages that will clutter the general python installation in your system. Usually people will use the famous virtualenv. However, it often brings trouble when you have to run 2 or more python environments simultaneously.
I'm about to share a simple trick that you can use to separate those environment, still using virtualenv but we're using it differently. The examples are in unix/linux, but the usage is quite similar in windows.
First, download virtualenv.py from https://raw.github.com/pypa/virtualenv/master/virtualenv.py.
That should be done in seconds.
Next up, create any folder where ever you want to create the virtual environment and copy the downloaded virtualenv.py file inside the folder.
Now, run the following command:
Installing package into the environment? Worry not, it's very simple.
simply run:
First, the fast way but a bit longer typing:
simply run:
I'm about to share a simple trick that you can use to separate those environment, still using virtualenv but we're using it differently. The examples are in unix/linux, but the usage is quite similar in windows.
First, download virtualenv.py from https://raw.github.com/pypa/virtualenv/master/virtualenv.py.
That should be done in seconds.
Next up, create any folder where ever you want to create the virtual environment and copy the downloaded virtualenv.py file inside the folder.
Now, run the following command:
python virtualenv.py envThat will create a folder called env inside your current folder and the folder will contain your newly created virtual environment.
Installing package into the environment? Worry not, it's very simple.
simply run:
env/bin/pip installafter installting the packages, write your python applications inside the folder. When you want to run the file, you have 2 ways of doing it:
simply run:
env/bin/python.py
Second, longer at first but takes less time if you have to repeat it on and on.
Add the following line in the topmost line of your file
afterwards to run it, you can simply call it this way:
In windows, change the env/bin/pip or env/bin/python into env/Scripts/pip or env/Scripts/python.
Hope that helps.
Happy hacking!!!
regards
-E-
follow @femmerling on twitter
Add the following line in the topmost line of your file
#! env/bin/pythonthen run
chmod a+x.py
afterwards to run it, you can simply call it this way:
./Aaaaand you're done! No need to change stop virtual environments to run the other and your global system is clutter free..py
In windows, change the env/bin/pip or env/bin/python into env/Scripts/pip or env/Scripts/python.
Hope that helps.
Happy hacking!!!
regards
-E-
follow @femmerling on twitter
Always yolk and freeze! Sometime egg is more important than a chkn.
ReplyDelete