How to let pip search dependency packages in local directory? [duplicate] - python
Here is the problem:
I have a requirements.txt file 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
bin/virtualenv testing
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 a later check revealed that none of the packages are installed properly. I cannot import the packages, and none are found in the site-packages directory of my virtualenv. So what went wrong?
This works for everyone:
pip install -r /path/to/requirements.txt
Explanation:
-r, --requirement < filename >
Install from the given requirements file. This option can be used multiple times.
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.
For virtualenv to install all files in the requirements.txt file.
cd to the directory where requirements.txt is located
activate your virtualenv
run: pip install -r requirements.txt in your shell
I had a similar problem. I tried this:
pip install -U -r requirements.txt
(-U = update if it had already installed)
But the problem continued. I realized that some of generic libraries for development were missed.
sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
I don't know if this would help you.
Use:
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 the pip install command):
Also the above is the complete set of options. Please use pip install --help for the complete list of options.
Short answer
pip install -r /path/to/requirements.txt
or in another form:
python -m pip install -r /path/to/requirements.txt
Explanation
Here, -r is short form of --requirement and it asks the pip to install from the given requirements file.
pip will start installation only after checking the availability of all listed items in the requirements file and it won't start installation even if one requirement is unavailable.
One workaround to install the available packages is installing listed packages one by one. Use the following command for that. A red color warning will be shown to notify you about the unavailable packages.
cat requirements.txt | xargs -n 1 pip install
To ignore comments (lines starting with a #) and blank lines, use:
cat requirements.txt | cut -f1 -d"#" | sed '/^\s*$/d' | xargs -n 1 pip install
First of all, create a virtual environment.
In Python 3.6
virtualenv --python=/usr/bin/python3.6 <path/to/new/virtualenv/>
In Python 2.7
virtualenv --python=/usr/bin/python2.7 <path/to/new/virtualenv/>
Then activate the environment and install all the packages available in the requirement.txt file.
source <path/to/new/virtualenv>/bin/activate
pip install -r <path/to/requirement.txt>
Often, you will want a fast install from local archives, without probing PyPI.
First, download the archives that fulfill your requirements:
$ pip install --download <DIR> -r requirements.txt
Then, install using –find-links and –no-index:
$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
Try this:
python -m pip install -r requirements.txt
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 /usr/local/lib/python3.6/site-packages while python is (python2.7 and) using /usr/local/lib/python2.7/site-packages
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."
Installing requirements.txt file inside virtual env with Python 3:
I had the same issue. I was trying to install the requirements.txt file inside a virtual environment. I found the solution.
Initially, I created my virtualenv in this way:
virtualenv -p python3 myenv
Activate the environment using:
source myenv/bin/activate
Now I installed the requirements.txt file using:
pip3 install -r requirements.txt
Installation was successful and I was able to import the modules.
Create virtual environment python3 -m venv virtual-env (For windows use python instead of python3)
Activate your virtual environment source virtual-env/bin/activate
Now install requirements pip install -r requirements.txt
pip install --user -r requirements.txt
OR
pip3 install --user -r requirements.txt
Use pip3 install -r requirements.txt But make sure the requirements.txt file has been pulled from origin and not added to .gitignore
In Windows, this can lead to less format-related path issues, if you have
c:\folder\subfolder\requirements.txt
cd c:\folder\subfolder
pip install -r requirements.txt
On windows Using this
pip install -r /path/to/requirements.txt
On linux pc we have python2 and also python3 so most time pip is regarded as
Python2
pip install -r /path/to/requirements.txt
Python 3
pip3 install -r /path/to/requirements.txt
While pip install -r requirements.txt works most of the time,
we sometimes face the problem that our requirements have conflicting dependencies.
You can install the packages line-by-line with the following one-liner:
while read -r line; do echo $line | cut -d' ' -f1 | xargs pip install; done < requirements.txt
Hope it helps someone!
Inside your project directory terminal write this:
$ pip freeze > requirements.txt
I have solved with running the below command:
py -m pip install ./requirements.txt
the above command will install all dependencies and libraries for the Django project.
Related
I got a ModuleNotFoundError when running a program cloned from one of my Github repos [duplicate]
Here is the problem: I have a requirements.txt file 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 bin/virtualenv testing 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 a later check revealed that none of the packages are installed properly. I cannot import the packages, and none are found in the site-packages directory of my virtualenv. So what went wrong?
This works for everyone: pip install -r /path/to/requirements.txt Explanation: -r, --requirement < filename > Install from the given requirements file. This option can be used multiple times.
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.
For virtualenv to install all files in the requirements.txt file. cd to the directory where requirements.txt is located activate your virtualenv run: pip install -r requirements.txt in your shell
I had a similar problem. I tried this: pip install -U -r requirements.txt (-U = update if it had already installed) But the problem continued. I realized that some of generic libraries for development were missed. sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk I don't know if this would help you.
Use: 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 the pip install command): Also the above is the complete set of options. Please use pip install --help for the complete list of options.
Short answer pip install -r /path/to/requirements.txt or in another form: python -m pip install -r /path/to/requirements.txt Explanation Here, -r is short form of --requirement and it asks the pip to install from the given requirements file. pip will start installation only after checking the availability of all listed items in the requirements file and it won't start installation even if one requirement is unavailable. One workaround to install the available packages is installing listed packages one by one. Use the following command for that. A red color warning will be shown to notify you about the unavailable packages. cat requirements.txt | xargs -n 1 pip install To ignore comments (lines starting with a #) and blank lines, use: cat requirements.txt | cut -f1 -d"#" | sed '/^\s*$/d' | xargs -n 1 pip install
First of all, create a virtual environment. In Python 3.6 virtualenv --python=/usr/bin/python3.6 <path/to/new/virtualenv/> In Python 2.7 virtualenv --python=/usr/bin/python2.7 <path/to/new/virtualenv/> Then activate the environment and install all the packages available in the requirement.txt file. source <path/to/new/virtualenv>/bin/activate pip install -r <path/to/requirement.txt>
Often, you will want a fast install from local archives, without probing PyPI. First, download the archives that fulfill your requirements: $ pip install --download <DIR> -r requirements.txt Then, install using –find-links and –no-index: $ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
Try this: python -m pip install -r requirements.txt
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 /usr/local/lib/python3.6/site-packages while python is (python2.7 and) using /usr/local/lib/python2.7/site-packages 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."
Installing requirements.txt file inside virtual env with Python 3: I had the same issue. I was trying to install the requirements.txt file inside a virtual environment. I found the solution. Initially, I created my virtualenv in this way: virtualenv -p python3 myenv Activate the environment using: source myenv/bin/activate Now I installed the requirements.txt file using: pip3 install -r requirements.txt Installation was successful and I was able to import the modules.
Create virtual environment python3 -m venv virtual-env (For windows use python instead of python3) Activate your virtual environment source virtual-env/bin/activate Now install requirements pip install -r requirements.txt
pip install --user -r requirements.txt OR pip3 install --user -r requirements.txt
Use pip3 install -r requirements.txt But make sure the requirements.txt file has been pulled from origin and not added to .gitignore
In Windows, this can lead to less format-related path issues, if you have c:\folder\subfolder\requirements.txt cd c:\folder\subfolder pip install -r requirements.txt
On windows Using this pip install -r /path/to/requirements.txt On linux pc we have python2 and also python3 so most time pip is regarded as Python2 pip install -r /path/to/requirements.txt Python 3 pip3 install -r /path/to/requirements.txt
While pip install -r requirements.txt works most of the time, we sometimes face the problem that our requirements have conflicting dependencies. You can install the packages line-by-line with the following one-liner: while read -r line; do echo $line | cut -d' ' -f1 | xargs pip install; done < requirements.txt Hope it helps someone!
Inside your project directory terminal write this: $ pip freeze > requirements.txt
I have solved with running the below command: py -m pip install ./requirements.txt the above command will install all dependencies and libraries for the Django project.
How to ignore the dependencies of a specific package when installing it with pipenv?
Is there a possibility to install a python package with pipenv without also installing the dependencies? I'm looking for an analogue of pip install package_name --no-dependencies for the Pipfile. I already tried to specify with a marker but it raises an exception. [packages] "psycopg2-binary" = "*" "aiopg"={version = "*", markers="--no-dependencies"}
Currently, pipenv does not support this. One workaround adds a script like the following to the end of Pipfile: [scripts] install = "sh -c 'pipenv install ; pip install --no-deps aiopg'" With this script, calling pipenv run install installs all dependencies from the [packages] section, including aiopg but excluding its dependencies.
I'm not sure pipenv supports that, but I think the following option may work (never tried it): Install via pip into a requirements.txt file pip install <package> --no-deps -r requirements.txt --> then import to pipenv pipenv install -r /path/to/requirements.txt If you already have a Pipfile in your current project, export your current pipenv file to a requirements.txt file pipenv lock -r > requirements.txt Combine the two files and then pipenv install from the combined requirements.txt file pipenv install -r path/to/requirements.txt Perhaps this link from the docs may help as well
Python PIP claims that a package is installed but whet I use package it is not found
I have been trying to setup a proper virtual environment. I came upon this. But I am still unable to use the package: yathi#DarkWater-U:~$ pip install virtualenvwrapper Requirement already satisfied (use --upgrade to upgrade): virtualenvwrapper in /usr/local/lib/python2.7/dist-packages Cleaning up... yathi#DarkWater-U:~$ workon workon: command not found yathi#DarkWater-U:~$ mkvirtualenv mkvirtualenv: command not found With some googling I found that the problem is probably because I used sudo pip install instead of pip install. But now I don't know how to correct the problem and install the package correctly.
Please read the documentation: $ pip install virtualenvwrapper ... $ export WORKON_HOME=~/Envs $ mkdir -p $WORKON_HOME $ source /usr/local/bin/virtualenvwrapper.sh $ mkvirtualenv env1
pip --find-links option doesn't seems to be working
When attempt to install from pip $ pip install Django==1.4 Most likely I get Error while getting http://pypi.python.org/packages/source/D/Django/Django-1.4.tar.gz#md5=ba8e86198a93c196015df0b363ab1109 (from http://pypi.python.org/simple/Django/) Per suggested by Jacob in his blog, I added --use-mirrors but no luck. Several comments made to this blog note that they are hosting file on their own. So I hosted tar.gz file to say example.com/packages directory. The command below successfully install Django 1.4 $ pip install https://example.com/packages/Django-1.4.tar.gz The commands below doesn't seems to be working and want to find out what am I doing wrong. $ pip install --find-links=https://example.com/packages/ Django==1.4 $ pip install --find-links "https://example.com/packages/" Django==1.4 $ pip install -f https://example.com/packages/ Django==1.4 Result in: Downloading/unpacking Django==1.4 Error while getting http://pypi.python.org/packages/source/D/Django/Django-1.4.tar.gz#md5=ba8e86198a93c196015df0b363ab1109 (from http://pypi.python.org/simple/Django/) Not sure why it appears to be ignoring --find-links option Apache auto-index is enabled for Packages directory hence pointing browser to https://example.com will return list of tar.gz files Any advice would be appriciated
pip fails to install packages from requirements.txt
I am trying to install a python software using the requirements file. >> cat requirements.txt Cython==0.15.1 numpy==1.6.1 distribute==0.6.24 logilab-astng==0.23.1logilab-common==0.57.1 netaddr==0.7.6 numexpr==2.0.1 ply==2.5 pycallgraph==0.5.1 pyflowtools==0.3.4.1 pylint==0.25.1 tables==2.3.1 wsgiref==0.1.2 So I create a virtual environment >> mkvirtualenv parser (parser) >> pip freeze distribute==0.6.24 wsgiref==0.1.2 (parser) >> pip install -r requirements.txt ... and then I packages downloaded but not installed with errors: http://pastie.org/4079800 (parser) >> pip freeze distribute==0.6.24 wsgiref==0.1.2 Surprisingly, if I try to manually install each package, they install just fine. For instance: >> pip install numpy==1.6.1 (parser) >> pip freeze distribute==0.6.24 wsgiref==0.1.2 numpy==1.6.1 I am lost. What is going on? PS: I am using pip v1.1 and python v2.7.2 with virtualenv and virtualenvwrapper
It looks like the numexpr package has an install-time dependency on numpy. Pip makes two passes through your requirements: first it downloads all packages and runs each one's setup.py to get its metadata, and then it installs them all in a second pass. So, numexpr is trying to import from numpy in its setup.py, but when pip first runs numexpr's setup.py, it has not yet installed numpy. This is also why you don't see this error when you install the packages one by one: if you install them one at a time, numpy will be fully installed in your environment before you pip install numexpr. The only solution is to install pip install numpy before you ever run pip install -r requirements.txt -- you won't be able to do this in a single command with a single requirements.txt file. More info here: https://github.com/pypa/pip/issues/25
I come across with a similar issue and I ended up with the below: cat requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 python -m pip install That will read line by line the requirements.txt and execute pip. I cannot find from where I got the answer properly, so apologies for that, but I found some justification below: How sed works: https://howto.lintel.in/truncate-empty-lines-using-sed/ Another similar answer but with git: https://stackoverflow.com/a/46494462/7127519 Hope this help with alternatives.
This is quite annoying sometimes, a bug of pip. When you run pip install package_name the pip will first run pip check to the target package, and install all the required package for the dependency(target package). But when you run pip install -r requirements.txt pip will try to directly install all the required packages listed one by one from top to bottom. Sometimes the dependency is listed above the package it depend upon. The solution is simple: 1.pip install package_name 2.simply put the error package to the bottom of the requirements.txt 3.sometimes a particular version of the package is not be able to be installed,just install the newest version of it and update the data in requirements.txt