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
Related
When trying to install pycURL using pip on Windows, I kept running into errors, so I decided to try to install it from the source on github. I'm using a virtual environment through anaconda3, and I'm wondering which folder/directory I need to clone into in order to get the installation to work?
Here's a photo of the virtual environment's directory.
following is my question/problem:
I am have installed python on two machine, machine A with internet ,machine B without internet.
I need to install packages(say for example pillow package) on machine B
I tried :pip download pillow ,on machine a in folder.
It created wheel file which does not work on machine B (some packages download as zip which can be installed on machine B ,but not one with wheel file.
I am trying route of virtual env.
On machine A I am doing :1. C:\pro1> myenv\scripts\activate
myenv C:\vi\pro1> pip install pillow
Taking the whole folder to machine B .
Assuming it should work as the package is in virtual env folder ,but it doesn't . :(
How can I make pillow package work on offline machine ?
Thank you.
Try to follow this. Obviously you must replace the packages with the ones you need.
virtualenv my-new-virtual-env
cd my-new-virtual-env
Activate the environment using the commands shown above.
For our convenience lets create in the root folder of the env a Wheelhouse/Tarhouse folder which will we install all our packages.
(Windows) mkdir Wheelhouse and afterwards cd Wheelhouse
(Linux) mkdir Tarhouse and afterwards cd Tarhouse
pip download virtualenv django numpy
pip freeze > requirements.txt
Take the downloaded .whl/.tar files to an offline station
Make sure you are in the root folder of the virtual envrionment and
issue the following command in your command line:
pip install -r requirements.txt --find-links=(Wheelhouse or Tarhouse)
I just wanted to add up that you can issue the command(if you want
install single package at a time):
pip install Wheelhouse/some-package-file.whl (or .tar on linux)
I am coming from NodeJS and learning Python and was wondering how to properly install the packages in requirements.txt file locally in the project.
For node, this is done by managing and installing the packages in package.json via npm install. However, the convention for Python project seems to be to add packages to a directory called lib. When I do pip install -r requirements.txt I think this does a global install on my computer, similar to nodes npm install -g global install. How can I install the dependencies of my requirements.txt file in a folder called lib?
use this command
pip install -r requirements.txt -t <path-to-the-lib-directory>
If you're looking to install dependencies in special (non-standard) local folder for a specific purpose (e.g. AWS Lambda), see this question: install python package at current directory.
For normal workflows the following is the way to install dependencies locally (instead of globally, equivalent to npm i instead of npm i -g in Node):
The recommended way to do this is by using a virtual environment. You can install virtualenv via pip with
pip install virtualenv
Then create a virtual environment in your project directory:
python3 -m venv env # previously: `virtualenv env`
Which will create a directory called env (you can call it anything you like though) which will mirror your global python installation. Inside env/ there will be a directory called lib which will contain Python and will store your dependencies.
Then activate the environment with:
source env/bin/activate
Then install your dependencies with pip and they will be installed in the virtual environment env/:
pip install -r requirements.txt
Then any time you return to the project, run source env/bin/activate again so that the dependencies can be found.
When you deploy your program, if the deployed environment is a physical server, or a virtual machine, you can follow the same process on the production machine. If the deployment environment is one of a few serverless environments (e.g. GCP App Engine), supplying a requirements.txt file will be sufficient. For some other serverless environments (e.g. AWS Lambda) the dependencies will need to be included in the root directory of the project. In that case, you should use pip install -r requirements.txt -t ./.
I would suggest getting the Anaconda navigator.
You can download it here: https://www.anaconda.com
Anaconda allows you to create virtual environments through a graphical interface. You can download any pip package that is available through Anaconda.
Then all you have to do after you have created and added onto your environment is to got to your designated python editor (I mainly use Pycharm) and setting the path to the virtual environment’s interpreter when you select or change the interpreter for your project.
Hope this helps.
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.
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