python生成以及安装项目配置文件

pip安装包、conda 安装环境 、linux修改conda镜像源、python生成以及安装项目配置文件


当我们在一台新的设备,或者新的环境中运行一个项目的时候,需要在环境中安装项目需要的配置文件,否则运行项目就会各种报错。这里介绍一种简单的安装“项目所需配置文件”得快速方法。

conda安装虚拟环境

1、创建虚拟环境

conda create --name you-env-name python=x.x.x
conda create -n you-env-name python=x.x.x

执行以上操作可能会报:…URL 错误,需要将镜像源改为国内镜像源。执行如下操作:

2、修改conda源(linux)

2.1、打开conda镜像源配置文件:

vim ~/.condarc

2.2、删除所有原内容,复制以下内容

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
注意,有时候换了镜像源还是会报错:
Solving environment: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/linux-64/repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(MaxRetryError('HTTPSConnectionPool(host=\'mirrors.tuna.tsinghua.edu.cn\', port=443): Max retries exceeded with url: /anaconda/cloud/menpo/linux-64/repodata.json (Caused by ReadTimeoutError("HTTPSConnectionPool(host=\'mirrors.tuna.tsinghua.edu.cn\', port=443): Read timed out. (read timeout=9.15)"))'))

!!!!需要把源的 https 换成 http

2.3、清除索引缓存(重要)

conda clean -i

再次执行创建虚拟环境语句

pip安装所需包

1、pip 安装

pip install some-package

2、pip国内镜像源(临时使用)

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

pip install some-package -i https://pypi.tuna.tsinghua.edu.cn/simple

生成配置文件

1、第一步:进入工程目录
运行环境中进入项目目录下:
在这里插入图片描述
在这里插入图片描述
2、安装如下模块:

pip install pipreqs

3、生成配置文件

pipreqs ./ --encoding='utf-8'

然后可以看到在项目目录中就产生了配置文件requirements

在这里插入图片描述在这里插入图片描述

安装配置文件

有了上边的配置文件,就可以在虚拟幻境或者新的设备环境中安装该项目所需要的配置文件
同样需要在环境中cd进入该项目然后:

pip install -r requirements.txt

在这里插入图片描述
补充:有时候生成文件的时候会报错:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘pypi.python.org’, port=443): Max retries exceeded with url: /pypi/Flask/json (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x000001C8926ACF40>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失 败。’))

这个是时候确保两点:

  • 程序没有在编译器中打开
  • 如果还是不行,可以将环境换成baes环境,生成文件以后再在虚拟环境重安装即可
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

企鹅家的北极熊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值