简体   繁体   English

如何从全局python环境创建一个conda环境?

[英]How to create a conda environment from global python environment?

Say I have a coworker who doesn't use conda, but instead uses a global python environment. 假设我有一个不使用conda的同事,而是使用全局python环境。

Is there a way for the coworker to use conda to create a conda environment from his global python environment? 有没有办法让同事使用conda从他的全球python环境创建一个conda环境?

The goal is for me to easily create a conda environment on my computer which matches his python environment. 我的目标是在我的计算机上轻松创建一个与他的python环境相匹配的conda环境。

On his side: 在他身边:

pip freeze > requirements.txt

On your side: 在你身边:

conda env create -n [ENV_NAME] -f requirements.txt


EDIT: This only works when 1) both environments are the latest python version, and 2) every package in the specific version that your coworker has, exists in conda. 编辑:这只适用于1)两个环境都是最新的python版本,以及2)你的同事拥有的特定版本中的每个包,都存在于conda中。 1 can be resolved through: 1可以通过以下方式解决:

conda create -n [ENV_NAME] python=[PYTHON_VER] -f requirements.txt

There isn't a one-step way to do 2 in conda afaik, what I would do is to (as stated in Lokinou's answer) first create a conda env in the desired python version, then install via pip: 在conda afaik中没有一步完成2的方法,我要做的是(如Lokinou的回答中所述)首先在所需的python版本中创建一个conda env,然后通过pip安装:

conda create -n [ENV_NAME] python=[PYTHON_VER]
conda activate [ENV_NAME]
pip install -r requirements.txt

You could ask your coworker to send his list of currently installed python packages using: 您可以要求您的同事使用以下命令发送当前安装的python包列表:

pip freeze > requirements.txt

Without forgetting a pip -V that returns his current version of python. 不要忘记返回当前版本的python的pip -V

When the conda environment is set up on your machine with the correct version of python, install the list of packages your coworker gave you: 当您的计算机上使用正确版本的python设置conda环境时,请安装您的同事给您的包列表:

pip install -r requirements.txt

It will only do the python part, so if additionnal libraries are needed, you might have to install them by hand (for example: c++ redistributables, Qt, imagemagick...) 它只会执行python部分,因此如果需要附加库,您可能需要手动安装它们(例如:c ++ redistributables,Qt,imagemagick ......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM