I'm using win7, python 2.7 and I have a project with several packages running.
I wanted to move the project to my friends laptop (which can't access to internet, not an option). so I downloaded Python/Django/All required packages, Installed python and run python setup.py install in each package directory.
I've found that some packages, even after I download them, requires somethings from the internet to be downloaded and causes error. so:
How can I download a package and all it's dependencies or what ever it needs to be installed offline?
This is how you can do it
Install Django and all related packages to a Python virtual environment
Run pip freeze > requirements.txt which will list all installed packages and their versions in this file
Use pip wheel -r requirements.txt command which builds a wheelhouse folder of the package list
Zip this folder
Go to your friend's computer, unzip
create virtual environment and run pip install wheelhouse/* (Install all packages from the wheelhouse)
More about pip wheel.
Python and pip needs to be separately copied and installed.
Related
I'm trying to install a python package from a private bitbucket repository into a virtual env, but pip does not seem to install any files. When using the following command (norman is the package's name):
pip3 install git+ssh://git#bitbucket.org/mycompany/myrepo.git#develop#egg=norman
the installation is successful but there is no norman folder in venv/lib/python3.6/site-packages/, so it seems that nothing was installed, even if venv/lib/python3.6/site-packages/norman=0.1.0.dist-info is indeed there.
Yet, the installation works perfectly using a tar.gz archive made with python3 setup.py sdist then installing with pip3 install path_to_norman.tar.gz.
Following these indications, I also tried to install the package in editable mode :
pip3 install -e git+ssh://git#bitbucket.org/mycompany/myrepo.git#develop#egg=norman
This worked fine and installed the files (in venv/src), but I'd prefer installing it in non-editable mode. What should I do to make the installation work in non-editable mode ?
The problem came from python __init__.py files which were not included in the remote repo, so the package installed by pip3 install git+ssh... was actually empty.
When building the archive on a local machine, they were obviously there, and when using -e option, as the whole repo is downloaded, the python scripts were there anyway.
When not using -e, from what I understand, pip creates a temporary local download of the files available and then builds the package normally. Since init files were not downloaded, python scripts were not recognized by setuptools, thus an empty package was installed.
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 question about python virtualenv. I get a virtualenv for a project with all packages required to run that project. But when i run it for the first time and it crash 'cause python has some requirements not satisfied. So i check if there is all packages inside:
virtualenv/lib/python2.7/site-packages/
and all packages required are inside.
But when i type:
pip list
packages doesn't shown. So i have to run:
pip install -r requirements.txt
pip downloads them again.
So my question is, why pip downloads and reinstall them again if they are installed yet ? And how i can force pip to reinstall all packages inside virtualenv ?
The problem was that all scripts inside the virtualenv were created on another pc with them paths. Indeed when i launched python or pip from virtualenv they ran from my global path 'cause couldn't find virtualenv script path and in particular pip shown my global packages.
Fixing directives path of all script inside virtualenb/bin/ to my real virtualenv path solved this issue.
I am new to using python, so bear with me if I make any assumptions.. So I have virtualenv and pip installed in my ubuntu machine. Every time I create a virtual environment I have to remotely download and install python modules(using pip install) such as django already installed in the main python package.
The problem is that I am not always connected to the internet. Is there a way I can load modules existing in the main Python to every virtual environment I create? Thanks!
You can pip download the Python packages you want to install offline and then install the .whl files in your virtualenv. Here is an example with Django and Requests:
Create a directory to store local Python packages:
mkdir local_python
Change directory: cd local_python
Download Python packages to be available offline:
pip download django requests
Install local package .whl files after you activate your virtualenv:
pip install Django-1.11.1-py2.py3-none-any.whl requests-2.16.5-py2.py3-none-any.whl
I am a bloody beginner in Python and Django. To set up a environment on my Windows machine, I performed the following steps.
Install Python 3.4
Use pip to install virtualenv
Create a project folder and set up a virtualenv there
Download Django 1.7b1 release from the official site
Extract the archive in my downloads folder
Install it into my virtualenv
For the last step, I used pip from my virtualenv.
[project]\scripts\pip.exe install -e [downloads]\Django-1.7b1
From the global python interpreter I can't import django, as expected. When using the python executable from the virtualenv, it works. But the import only succeeds as long as I have the Django source in my downloads folder. Instead, I would like to include it into my virtualenv.
Can I make pip to automatically copy the Django source into my project folder?
Install django via pip inside the virtualenv. I'm running Linux but you should be able to run the commands on windows.
If you need a version that's not in PyPi, download the package and install it to the virtualenv site-packages-folder.
My site-packages folder for project is in ~/venvs/project/lib/python2.7/site-packages.
To install there:
pip install downloads/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages
Django will install to the site-packages folder and is now importable from within the virtualenv. Downloads/Django-1.7b1 is no longer needed.
Below is an example where I'm installing Django 1.7b1 from a local archive to the site-packages-folder of my virtualenv:
(project)msvalkon#Lunkwill:/tmp$ pip install /tmp/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages/
Unpacking ./Django-1.7b1.tar.gz
Running setup.py egg_info for package from file:///tmp/Django-1.7b1.tar.gz
-- SNIP --
Successfully installed Django
Cleaning up...
(project)msvalkon#Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.7b1
(project)msvalkon#Lunkwill:/tmp$ deactivate
# I've got a really old version installed globally, but you can see
# that the installation worked.
msvalkon#Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.5.1
After this you should find the following output when doing pip freeze while the virtualenv
is activated:
(project)msvalkon#Lunkwill:/tmp$ pip freeze
Django==1.7b1
argparse==1.2.1
wsgiref==0.1.2