Python:conda离线安装python环境

文章目录

    • @[toc]
    • 一、需求
    • 二、解决
      • 1.新建环境名
      • 2.进入环境
      • 3.安装python
      • 4.查看python
      • 5.安装pip
    • 三、安装openssl
      • 1.下载openssl
      • 2.解压缩:
      • 3.cd openssl-1.1.1g
      • 4.配置
      • 5.make
      • 6.make test
      • 7.make install
      • 8.编辑~/.bash_profile,或者~/.bash_rc,
    • 其他:

一、需求

在离线环境下,使用anaconda创建环境的时候,需要指定Python的版本,但是无法自动下载,需要手动下载Python包,然后用conda进行安装。

在这里插入图片描述

二、解决

首先下载Python包,在https://repo.anaconda.com/中选择Anaconda Packages 。

在这里插入图片描述

可以看到里面有Python包也有R包还有Microsoft R Open等一些包,然后选择Python的相关包:

在这里插入图片描述

最终打开的页面:

在这里插入图片描述

也可以通过https://repo.anaconda.com/pkgs/main/linux-64/直接打开。
这里我选择了python-3.6.13-h12debd9_1.tar.bz2, 同时安装pip, pip-20.3-py36h06a4308_0.tar.bz2

1.新建环境名

在~/anaconda3/envs/目录下,新建一个空文件夹,目录名为环境名,使用conda env list 查看环境列表时并不会显示该环境名称;这里我创建一个test环境名。

在这里插入图片描述

2.进入环境

但是可以进入新建的环境:使用conda activate +环境名进入新环境;

在这里插入图片描述

有时候提示Use ‘conda create’ to convert the directory to a conda environment. 这时需要通过conda create --name test --offline 来创建一个空环境

3.安装python

然后在当前环境下安装Python:conda install python-3.6.13-h12debd9_1.tar.bz2

可以使用命令conda install python-3.6.13-h12debd9_1.tar.bz2 --offline 来解决有时候会报错:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘repo.anaconda.com’, port=443): Max retries exceeded with url: /pkgs/main/notices.json (Caused by NewConnectionError(‘: Failed to establish a new connection: [Errno 101] Network is unreachable’))

在这里插入图片描述

4.查看python

在新的环境中可以看到安装的Python

在这里插入图片描述

5.安装pip

conda install pip-20.3-py36h06a4308_0.tar.bz2

在这里插入图片描述

6.此时安装的pip位于新建环境中,输入pip --version 查看pip应位于新建环境目录下。

在这里插入图片描述

三、安装openssl

如果我们用pip安装一个Python包的时候会报错:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

需要安装openssl

1.下载openssl

wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz

2.解压缩:

tar -xvf openssl-1.1.1g.tar.gz

3.cd openssl-1.1.1g

4.配置

./config --prefix=/home/用户名/openssl --openssldir=/home/用户名/openssl no-ssl2

5.make

6.make test

运行结果显式成功

7.make install

8.编辑/.bash_profile,或者/.bash_rc,

添加内容:

export PATH=$HOME/openssl/bin:$PATH
export LD_LIBRARY_PATH=$HOME/openssl/lib
export LC_ALL="en_US.UTF-8"
export LDFLAGS="-L /home/用户名/openssl/lib -Wl,-rpath,/home/用户名/openssl/lib"

source ~/.bash_profile或者source ~/.bash_rc

在这里插入图片描述

这样就可以用pip安装Python包了。

其他:

参考:https://blog.csdn.net/vincent_duan/article/details/126382001

你可能感兴趣的:(一周专栏:Python专栏,python,conda,离线安装)