Reputation: 59395
I'm confused about virtualenv
. I've been reading docs and trying examples, but its not getting better.
I created a virtualenv
in the following way:
$ virtualenv myapp_venv --no-site-package
I used --no-site-packages
because I want to know that that my requirements.txt
is sufficient for building and running my code. I don't want to depend on whatever may be installed on my dev machine.
Then I try to install dependencies into my virtualenv
:
$ source myapp_venv/bin/activate
(myapp_venv) $ sudo pip install -r requirements.txt
At this point I get a number of messages like this:
Requirement already satisfied (use --upgrade to upgrade): Flask==0.10.1 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 1))
This surprises me, as I thought virtualenv
would not be concerned with globally available packages, but with the environment of this project.
When I proceed to try to run the application:
(myapp_venv) $ python run.py
Traceback (most recent call last):
File "run.py", line 1, in <module>
from app import app
File "/home/eric/code/python/tournament/app/__init__.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
But if I deactivate the virtualenv
, the app runs just fine.
How can I git pip
to install the packages into the virtualenv
?
For context, I'm professionally experienced with Java/Maven. I have a bit of Python language experience, but the Python ecosystem is still new to me.
Upvotes: 0
Views: 158
Reputation: 2555
Check no-global-site-packages.txt
in your lib
.
If no-global-site-packages.txt
file is in lib
folder, then It will take all packages from your virtualenv
else It will take globally.
Also, As wissam said, don't use sudo
. It is correct. because using sudo
, It will install globally.
Upvotes: 0
Reputation: 830
Skip the sudo, and you will be fine. Sudo is telling to install globally.
Upvotes: 2