How to download python without network in linux environment
- 2021-07-10 20:16:22
- OfStack
Sometimes you need to build an environment when you can't connect to the Internet, and you must use the previous environment, because your code needs to run in the same environment. This is convenient for development
Method 1:
1. Downloads the specified package to the specified folder.
pip list # View installed packages
pip freeze > requirements.txt Will have passed pip The name of the installed package is logged to the requirements.txt In a file
Create a directory to store the installation package: mkdir /packs
pip install --download /packs pandas( Storage 1 A pandas Bag )
Or
pip install --download /packs -r requirements.txt (Storage requirements.txt All packages listed)
2. Installs the specified offline package
pip install --no-index --find-links=/packs/ pandas Or
pip install --no-index --find-links=/packs/ -r requirements.txt (It may also be --find-link)
However, this method will have many problems after my test. For example, in pip install-download/packs-r requirements. txt, some packages may not be downloaded, and the installation on the new server after downloading the packages may lack dependencies and be unsuccessful.
Method 2:
That is to use the integrated environment-Anaconda, which is super simple to install, because it is a packaged environment, and the third party package of python that you download and install later is in this environment, so you only need to copy the installed Anconda package to the server that is not networked (of course, it needs to be configured on. bashrc).
Step 1 Install Anconda now:
Download the Anconda installation package from official website, where I use Anaconda3-5. 2.0-Linux-x86_64. sh.
bash Anaconda3-5.2.0-Linux-x86_64.sh
1 way Enter, Y, and then remind you to configure the environment
echo 'export PATH="/home/wwk/anaconda3/bin:$PATH"' >> ~/.bashrc
source .bashrc
Of course, you are also allowed to choose the installation path. If you choose OK by default, now verify whether the installation is successful
conda -V
If the version number appears, it is successful.
Step 2 Install the packages you need:
Anconda integrates pip and conda. Of course, both of them can download various packages, such as pip isntall somepackage, conda install somepackage. However, when downloading with conda command, there may be a problem. If the installation package you need is not 1, it will definitely hit (because the domestic mirror channel may not be found). Take py2neo package as an example
wwk@wwk-Aspire-V3-572G:~$ conda install py2neo
Fetching package metadata .............
PackageNotFoundError: Packages missing in current channels:
- py2neo
We have searched for the packages in the following channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
- https://repo.continuum.io/pkgs/main/linux-64
- https://repo.continuum.io/pkgs/main/noarch
- https://repo.continuum.io/pkgs/free/linux-64
- https://repo.continuum.io/pkgs/free/noarch
- https://repo.continuum.io/pkgs/r/linux-64
- https://repo.continuum.io/pkgs/r/noarch
- https://repo.continuum.io/pkgs/pro/linux-64
- https://repo.continuum.io/pkgs/pro/noarch
So we have two ways:
1. For the most direct words, we directly download the installation packages we need from other ways, such as downloading zip from github, decompressing tar. gz and other compressed packages, then entering the decompression directory and installing them with python setup. py install command (note that which python is needed to see if the environment is in anconda at this time, so as to ensure installation in anconda environment). In fact, it is also convenient to install pip directly (embedded in anconda).
2. Then, to solve the above problems, input: anaconda search-t conda py2neo
wwk@wwk-Aspire-V3-572G:~$ anaconda search -t conda py2neo
Using Anaconda API: https://api.anaconda.org
Packages:
Name | Version | Package Types | Platforms | Builds
------------------------- | ------ | --------------- | --------------- | ----------
auto/py2neo | 1.6.4 | conda | linux-64, linux-32 | py27_0
: http://nigelsmall.com/py2neo
bioconda-legacy/py2neo | 3.1.2 | conda | linux-64, osx-64 | py36_0, py27_0, py35_0, py34_0
cmckeague/py2neo | 3b1 | conda | linux-armv7l | py27_0
: Python client library and toolkit for Neo4j
conda-forge/py2neo | 4.0.0b2 | conda | linux-64, win-32, osx-64, win-64 | py36_0, py35_0, py27_0
: Python client library and toolkit for Neo4j
ivoflipse/py2neo | 1.6.4 | pypi, conda | win-64 | py27_0
: Python client library for the Neo4j REST server
mutirri/py2neo | 2.0.8 | conda | linux-64, win-32, win-64, osx-64 | py27_0, py33_0, py35_0, py34_0
: Python client library and toolkit for Neo4j
Found 6 packages
Run 'anaconda show <USER/PACKAGE>' to get installation details
Then enter: anaconda show conda-forge/py2neo to see the channel where you want to install the package
wwk@wwk-Aspire-V3-572G:~$ anaconda show conda-forge/py2neo
Using Anaconda API: https://api.anaconda.org
Name: py2neo
Summary: Python client library and toolkit for Neo4j
Access: public
Package Types: conda
Versions:
+ 4.0.0b2
+ 3.1.2
To install this package with conda run:
conda install --channel https://conda.anaconda.org/conda-forge py2neo
We can enter copy according to the prompt in the last line
wwk@wwk-Aspire-V3-572G:~$ conda install --channel https://conda.anaconda.org/conda-forge py2neo
Fetching package metadata ...............
Solving package specifications: .
Package plan for installation in environment /home/wwk/anaconda3:
The following NEW packages will be INSTALLED:
neo4j-python-driver: 1.1.0rc1-py36_0 conda-forge
py2neo: 4.0.0b2-py36_0 conda-forge
The following packages will be UPDATED:
conda: 4.3.30-py36h5d9f9f4_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 4.5.11-py36_0 conda-forge
conda-env: 2.6.0-0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 2.6.0-1 conda-forge
Proceed ([y]/n)? y
conda-env-2.6. 100% |#####################################################################| Time: 0:00:00 1.34 MB/s
neo4j-python-d 100% |#####################################################################| Time: 0:00:00 72.70 kB/s
py2neo-4.0.0b2 100% |#####################################################################| Time: 0:00:00 176.24 kB/s
conda-4.5.11-p 100% |#####################################################################| Time: 0:00:02 230.86 kB/s
Finally, don't forget to open the python environment import package and try whether it is successful.
The above operations are to completely arrange your operating environment in a networked environment. So congratulations, you're 99% done
Step 3: Compress and package the installed anconda3. anconda3. zip and copy it to the server you want to install, which is not connected to the network. I put the/home/wwk/anaconda3
Finally:
unizp anaconda3.zip -d /home/wwk/anaconda3
vim .bashrc
# added by Anaconda3 installer
export PATH="/home/wwk/anaconda3/bin:$PATH"