I created a virtualenv with the following command.
mkvirtualenv --distribute --system-site-packages "$1"
After starting the virtualenv with workon
, I type ipython
. It prompts me
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
When I try to install ipython with the virtualenv, I got the following error message:
pip install ipython
Requirement already satisfied (use --upgrade to upgrade): ipython in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
Does anyone know how to install inside the virtualenv?
Sharing what has worked for me in both Ubuntu and Windows. This is for python3. To do for python2, replace "3" with "2":
Ubuntu
To install any package:
pip install package
To get out of the virtual environment:
deactivate
To activate again:
source /tmp/VIRTUAL/bin/activate
Full explanation here.
Windows
(Assuming you have MiniConda installed and are in the Start Menu > Anaconda > Anaconda Terminal)
To install any package:
pip install package
orconda install package
To get out of the virtual environment:
deactivate
To activate again:
activate VIRTUAL
Full explanation here.
To further clarify the other answer here:
Under the current version of virtualenv, the --no-site-packages flag is the default behavior, so you don't need to specify it. However, you are overriding the default by explicitly using the --system-site-packages flag, and that's probably not what you want. The default behavior (without specifying either flag) is to create the virtual environment such that when you are using it, any Python packages installed outside the environment are not accessible. That's typically the right choice because it best isolates the virtual environment from your local computer environment. Python packages installed within the environment will not affect your local computer and vice versa.
Secondly, to use a virtual environment after it's been created, you need to navigate into the virtual environment directory and then run:
What this does is to configure environment variables so that Python packages and any executables in the virtual environment's bin folders will be used before those in the standard locations on your local computer. So, for example, when you type "pip", the version of pip that is inside your virtual environment will run instead of the version of pip on your local machine. This is desirable because pip inside the virtual environment will install packages inside the virtual environment.
The problem you are having is because you are running programs (like ipython) from your local machine, when you instead want to install and run copies of those programs isolated inside your virtual environment. You set this up by creating the environment (without specifying any site-packages flags if you are using the current version), running the activate script mentioned above, then running pip to install any packages you need (which will go inside the environment).
Create your virtualenv with
--no-site-packages
if you don't want it to be able to use external libraries:Otherwise, as in your example, it can see a library installed in your system Python environment as satisfying your requested dependency.
I tried here to give an answer, with a complete view and also with some good tips.
So, here are some instructions that could avoid headaches when using Virtual Environments:
For a better representation of these practices, here's a simulation:
creating a folder for your projects/environments
creating environment
activating environment
installing packages
package available inside the environment
deactivate environment
package NOT AVAILABLE outside the environment
Notes:
Why not sudo?
If you rename the folder of your project...
I had the same issue and the
--no-site-packages
did not work for me. I discovered on this older mailing list archive that you are able to force an installation in the virtualenv using the-U
flag for pip, egpip -U ipython
. You may verify this works using the bash commandwhich ipython
while in the virtualenv.source: https://mail.python.org/pipermail/python-list/2010-March/571663.html
For Python 3 :