working - requirements.txt python version
How to install packages using pip according to the requirements.txt file from a local directory? (6)
Here is the problem
I have a requirements.txt that looks like:
BeautifulSoup==3.2.0 Django==1.3 Fabric==1.2.0 Jinja2==2.5.5 PyYAML==3.09 Pygments==1.4 SQLAlchemy==0.7.1 South==0.7.3 amqplib==0.6.1 anyjson==0.3 ...
I have a local archive directory containing all the packages + others.
I have created a new virtualenv with
upon activating it, I tried to install the packages according to requirements.txt from the local archive directory.
source bin/activate pip install -r /path/to/requirements.txt -f file:///path/to/archive/
I got some output that seems to indicate that the installation is fine
Downloading/unpacking Fabric==1.2.0 (from -r ../testing/requirements.txt (line 3)) Running setup.py egg_info for package Fabric warning: no previously-included files matching '*' found under directory 'docs/_build' warning: no files found matching 'fabfile.py' Downloading/unpacking South==0.7.3 (from -r ../testing/requirements.txt (line 8)) Running setup.py egg_info for package South ....
But later check revealed none of the package is installed properly. I cannot import the package, and none is found in the site-packages directory of my virtualenv. So what went wrong?
Installing requirements.txt file inside virtual env with python 3:
I had the same issue. I was trying to install requirements.txt file inside a virtual environament. I found the solution.
Initially, I created my virtual env in this way:
virtualenv -p python3 myenv
Activate the environment using:
Now I installed the requirements.txt using:
pip3 install -r requirements.txt
Installation was successful and I was able to import the modules.
For virtualenv to install all files in the requirements.txt file.
- cd to the directory where requirements.txt is located
- activate your virtualenv
pip install -r requirements.txtin your shell
I work with a lot of systems that have been mucked by developers "following directions they found on the internet". It is extremely common that your
pip and your
python are not looking at the same paths/site-packages. For this reason, when I encounter oddness I start by doing this:
$ python -c 'import sys; print(sys.path)' ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages'] $ pip --version pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
That is a happy system.
Below is an unhappy system. (Or at least it's a blissfully ignorant system that causes others to be unhappy.)
$ pip --version pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6) $ python -c 'import sys; print(sys.path)' ['', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] $ which pip pip2 pip3 /usr/local/bin/pip /usr/local/bin/pip3
It is unhappy because
pip is (python3.6 and) using
python is (python2.7 and) using
When I want to make sure I'm installing requirements to the right python, I do this:
$ which -a python python2 python3 /usr/local/bin/python /usr/bin/python /usr/local/bin/python2 /usr/local/bin/python3 $ /usr/bin/python -m pip install -r requirements.txt
You've heard, "If it ain't broke, don't try to fix it." The DevOps version of that is, "If you didn't break it and you can work around it, don't try to fix it."
I've read the above, realize this is an old question, but it's totally unresolved and still at the top of my google search results so here's an answer that works for everyone:
pip install -r /path/to/requirements.txt
This works for me:
$ pip install -r requirements.txt --no-index --find-links file:///tmp/packages
--no-index - Ignore package index (only looking at
--find-links URLs instead).
-f, --find-links <URL> - If a URL or path to an html file, then parse for links to archives.
If a local path or
file:// URL that's a directory, then look for archives in the directory listing.
pip install -r requirements.txt
For further details please check the help option.
pip install --help
We can find the option '-r'
-r, --requirement Install from the given requirements file. This option can be used multiple times.
Further information on some commonly used pip install options: (This is the help option on pip install command)
Also the above is the complete set of options. Please use pip install --help for complete list of options.