Copy installed packages using pip to another environment - python

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

Related

How to tell pip to install all packages in build-system.requires

I am transitioning from requirements.txt to pyproject.toml
In it I specified a list of required packages in project.dependencies, and the same list + additional packages in build-system.requires.
However if I run:
python -m pip install .
It seems to install only packages listed in project.dependencies
How do I tell pip to install all packages listed in build-system.requires ?

how to reinstall a python environment offline?

I have server without Internet connection. I would to copy the current python environment from another machine (installed by pip and conda) to this server by disk. That is I need to know which packages are installed, download these package and reinstall these package in the server. Is there any way to manage the whole process automatically?
thanks in advance.
Use pip freeze to create a list of installed packages and pip download to download them. Move them to your offline location and install them all with pip install:
$ pip freeze > requirements.txt
$ pip download -r ../requirements.txt -d packages
$ # move packages/* to offline host
offline_host$ pip install packages/*

pip install -r requirements to a specific directory in Colab

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"

Install Test Python Package in Different directory Using Pip

I have a python distutils module that I use in production. I have that production module installed in a virtual environment. However, I'd like to be able to test upgrades before installing in the production environment. I'm also trying to avoid creating a second virtual environment. Therefore I tried the following:
# inside my virtualenv
# checkout master of my repo
git clone git+git://github.com/myrepo
cd myrepo
# create directory where my testing install will live
mkdir testinstall
# prepend my testing install to the PYTHONPATH to over-ride the
# production install of my repo
export PYTHONPATH=$PWD/testinstall/lib/python2.7/site-packages:$PYTHONPATH
# install my local package with pip into the test area
pip install --prefix=$PWD/testinstall .
In this case I get the error from pip:
Requirement already satisfied from /path/to/production/myrepo
If I use
pip install --upgrade --prefix=$PWD/testinstall
pip proceeds to uninstall the production version from /path/to/production/myrepo and install my test version in the testinstall area.
Any idea how to force pip to install in this way?
Try doing it this way instead
pip install --target=d:\somewhere\other\than\the\default package_name
I'd just use a new venv but if you really can't, use the -t (target) option.
pip3 install --upgrade -t my_new_directory

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...

Categories

Resources