How to install packages offline?

后端 未结 10 897
一个人的身影
一个人的身影 2020-11-22 00:38

What\'s the best way to download a python package and it\'s dependencies from pypi for offline installation on another machine? Is there any easy way to do this with pip or

相关标签:
10条回答
  • 2020-11-22 01:14

    offline python. for doing this I use virtualenv (isolated Python environment)

    1) install virtualenv online with pip:

    pip install virtualenv --user
    

    or offline with whl: go to this link , download last version (.whl or tar.gz) and install that with this command:

    pip install virtualenv-15.1.0-py2.py3-none-any.whl --user
    

    by using --user you don't need to use sudo pip….

    2) use virtualenv

    on online machine select a directory with terminal cd and run this code:

    python -m virtualenv myenv
    cd myenv
    source bin/activate
    pip install Flask
    

    after installing all the packages, you have to generate a requirements.txt so while your virtualenv is active, write

    pip freeze > requirements.txt
    

    open a new terminal and create another env like myenv2.

    python -m virtualenv myenv2
    cd myenv2
    source bin/activate
    cd -
    ls
    

    now you can go to your offline folder where your requirements.txt and tranferred_packages folder are in there. download the packages with following code and put all of them to tranferred_packages folder.

    pip download -r requirements.txt
    

    take your offline folder to offline computer and then

    python -m virtualenv myenv2
    cd myenv2
    source bin/activate
    cd -
    cd offline
    pip install --no-index --find-links="./tranferred_packages" -r requirements.txt
    

    what is in the folder offline [requirements.txt , tranferred_packages {Flask-0.10.1.tar.gz, ...}]

    check list of your package

    pip list
    

    note: as we are in 2017 it is better to use python 3. you can create python 3 virtualenv with this command.

    virtualenv -p python3 envname
    
    0 讨论(0)
  • 2020-11-22 01:18

    Download the wheel file (for example dlb-0.5.0-py3-none-any.whl) from Pypi and

    pip install dlb-0.5.0-py3-none-any.whl
    
    0 讨论(0)
  • 2020-11-22 01:21

    If you want install python libs and their dependencies offline, finish following these steps on a machine with the same os, network connected, and python installed:

    1) Create a requirements.txt file with similar content (Note - these are the libraries you wish to download):

    Flask==0.12
    requests>=2.7.0
    scikit-learn==0.19.1
    numpy==1.14.3
    pandas==0.22.0
    

    One option for creating the requirements file is to use pip freeze > requirements.txt. This will list all libraries in your environment. Then you can go in to requirements.txt and remove un-needed ones.

    2) Execute command mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse to download libs and their dependencies to directory wheelhouse

    3) Copy requirements.txt into wheelhouse directory

    4) Archive wheelhouse into wheelhouse.tar.gz with tar -zcf wheelhouse.tar.gz wheelhouse

    Then upload wheelhouse.tar.gz to your target machine:

    1) Execute tar -zxf wheelhouse.tar.gz to extract the files

    2) Execute pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse to install the libs and their dependencies

    0 讨论(0)
  • 2020-11-22 01:27

    Let me go through the process step by step:

    1. On a computer connected to the internet, create a folder.
       $ mkdir packages
       $ cd packages
    
    1. open up a command prompt or shell and execute the following command:

      Suppose the package you want is tensorflow

      $ pip download tensorflow

    2. Now, on the target computer, copy the packages folder and apply the following command

      $ cd packages
      $ pip install 'tensorflow-xyz.whl' --no-index --find-links '.'
    

    Note that the tensorflow-xyz.whl must be replaced by the original name of the required package.

    0 讨论(0)
提交回复
热议问题