pip install -r requirements to a specific directory in Colab - python

I have found that I can pip install packages to a certain directory using:
!pip install --target='/content/drive/Mydrive/requirements' <package_name>
In the above case, I can see <package_name> in the folder '/content/drive/Mydrive/requirements'. However, when I install packages from a file, 'requirements.txt', the packages do not go into the target directory, namely:
!pip install --target='/content/drive/Mydrive/requirements' -r requirements.txt
Does not install the packages in 'requirements.txt' into '/content/drive/Mydrive/requirements'.
Can somebody please help? Thanks!

I realized what was needed ... (below)
!pip install -r requirements.txt -t "target_dir"
I think where the "-r" flag is seemed to matter, but then again I had tried that but it didn't work before. However, what I have here does work.

pip3 install "package_name" -t "target_dir"

Related

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

Copy installed packages using pip to another environment

I downloaded some packages in my environment using pip command. And I want to have a copy of them to transfer them to another environment. I know that using:
pip freeze > requirements.txt
will generate requirements into a file, but since my second environment does not have access to internet i can not use:
pip install -r requirements.txt
to install that packages again.
Is there any way to copy installed packages? or somehow install packages in a specified directory in my first environment?
Thanks
You can use pip download followed by pip install --find-links to achieve what you want.Here is the steps involved
Get the requirements
pip freeze>requirements.txt
Download the packages to a folder
pip download -r requirements.txt -d path_to_the_folder
From the new environment
pip install -r requirements.txt --find-links=path_to_the_folder

How to change the install path for PIP

I got my pip install directory in
/Library/Python/2.7/site-packages
Somehow, after I install the wordbatch library, my pip install path changes to
/usr/local/lib/python2.7/site-packages
Does anyone know how to change the pip install path?
One idea is you can just install it anywere. Then move it to the correct directory. This should fix the problem, if you want it to install there from the start. Then i don't know.
You can see help of pip install in bash like pip install --help.
Current task you need use parameters --target /usr/local/lib/python2.7/site-packages.

How to save pip packages

We have a python/django based web application, many components of which are installed using pip. So I would like to ask if there is a way to save or download and save the particular python packages that we are having pip install (example: pip install django==1.5.1). We would like to have in the end a collection of the packages in the versions known to be working and with which the app was developed locally. Any and all advice will be appreciated.
If I understood your question right, you can pip freeze > requirements.txt, this command will add all the libraries you have used/"downloaded" for your app in the file requirements.txt(in case it exists the file be overwritten). This command allows you to later do pip install -r requirements.txt. However, be aware that your Django project must be running in a virtual environment, otherwise the install command will attempt to install all the python packages in your development machine.
The freeze command will allow you to have the current version of the app so upon installation will attempt to install that same version. Your requirements file will look something like:
Flask==0.8
Jinja2==2.6
Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1
distribute==0.6.24
gunicorn==0.14.2
requests==0.11.1
Your packages are installed (if using virtualenv) at: ../<your project>/<your virtual env>/<lib>/<python version>/<site-packages>/
As for downloading you can use pip install --download command as #atupal suggested in his response, however think if this is really needed you can also fork those libraries on github to accomplish the same.
Here is a good source of information on how this works: http://www.pip-installer.org/en/latest/cookbook.html
Maybe what you want is:
Download the packages:
pip install --download /path/to/download/to packagename
OR
pip install --download=/path/to/packages/downloaded -r requirements.txt
install all of those libraries just downloaded:
pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename
OR
pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt
Shamelessly stolen from this question
Create a requirements.txt file.
Put:
django==1.5.1
in the first line.
Then run pip install -r requirements.txt
Then you can complete that file...

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

Categories

Resources