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/*
Related
I want to install some packages on the server which does not access to internet. so I have to take packages and send them to the server. But I do not know how can I install them.
Download all the packages you need and send them to the server where you need to install them. It doesn't matter if they have *whl or *tar.gz extension. Then install them one by one using pip:
pip install path/to/package
or:
python -m pip install path/to/package
The second option is useful if you have multiple interpreters on the server (e.g. python2 and python3 or multiple versions of either of them). In such case replace python with the one you want to use, e.g:
python3 -m pip install path/to/package
If you have a lot of packages, you can list them in a requirement file as you would normally do when you have access to the internet. Then instead of putting the names of the packages into the file, put the paths to the packages (one path per line). When you have the file, install all packages by typing:
python -m pip install -r requirements.txt
In the requirements file you can also mix between different types of the packages (*whl and *tar.gz). The only thing to take care about is to download the correct versions of the packages you need for the platform you have (64bit packages for 64bit platform etc.).
You can find more information regarding pip install in its documentation.
You can either download the packages from the website and run python setup.py install. Or you can run a pip install on a local dir, such as :
pip install path/to/tar/ball
https://pip.pypa.io/en/stable/reference/pip_install/#usage
Download the wheel packages from https://www.lfd.uci.edu/~gohlke/pythonlibs/ . You may install the .whl packages by pip install (package.whl) , refer installing wheels using pip for more.
Download the package from website and extract the tar ball.
run python setup.py install
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
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
I'm using a virtualenv to run Python 2.7 in my local machine and everything works as expected. When I transfer "site-packages" to my production sever, I get the follow error:
PIL/_imaging.so: invalid ELF header
This happens on the Pillow 2.5.3 pypi package found here
I am running OS X, while my production server is running Debian. I suspect the OS differences might be causing the issue but I'm not sure. I have no idea how to fix this. Can anyone help?
Note: I cannot install packages directly to my production server, so I have to upload them directly to use them.
In your current virtual environment, execute the following command
pip freeze > requirements.txt
Copy this requirements.txt file to your server.
Create your new virtualenvironment (delete the one you were using before).
Activate the virtual environment and then type pip install -r requirements.txt
Now, the libraries will be installed correctly and built accurately as well.
If you see errors for PIL, execute the following commands:
sudo apt-get install build-essential python-dev
sudo apt-get build-dep python-imaging
virtual environments are for isolating Python on your current machine; they are not for creating portable environments. The benefit is to work with different versions of Python packages without modifying the system Python installation.
Using virtual environments does not require super-user permissions; so you can install packages even if you are not "root".
It does, however, require Internet access as packages are downloaded from the web. If your server does not have access to the Internet, back on your mac, do the following, from your virtual environment:
pip install basket
This will install basket which is a small utility that allows you to download packages but not install them. Great for keeping a local archive of packages that you can move to other machines.
Once its installed, follow these steps as listed in the documentation:
basket init
pip freeze > requirements.txt
awk -F'==' '{print $1}' requirements.txt | basket download
This will download all the packages from your requirements.txt file into ~/.basket
Next, copy this directory to your server and then run the following command from your virtualenvironment
pip install --no-index -f /path/to/basket -r requirements.txt
I have a pip requirements file with pinned package versions. I need to install PyPI packages on a system without a direct internet connection. How can I easily download the packages I need now, for pip installation later, without visiting each package page myself?
The pip documentation has a good example of fast and local installs:
$ pip install --download <DIR> -r requirements.txt
$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
This is mostly for speed, but if you do the first step on an internet connected machine, copy the files to the other machine, then run the second step, you should be able to install all of your requirements without an internet connection.
To add to ford's answer, in order to get around cross-platform issues one can do the following instead:
On the machine with internet access do:
$ pip install --download <DIR> -r requirements.txt
$ pip install --download <DIR> -r requirements.txt --no-use-wheel
This will download available wheels for the packages in case the wheel is cross platform, but will also download the source so the packages can be built on any platform in case the wheel doesn't work for the target system.
Then, as ford has suggested, after moving the from the machine with internet access to the other machine do:
$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
I can't guarantee this will work in every case, but it worked for me when trying to download a package and its dependencies on a Windows machine with internet access to install on a CentOS machine without internet access. There may also be other factors to consider if using different versions of Python on each machine (in my case I had Python 3.4 on both).