在另一台计算机上复制Python环境 [英] Replicate Python environment on another computer

查看:115
本文介绍了在另一台计算机上复制Python环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Windows计算机的python环境设置复制到另一台计算机上,并能够成功运行非常特定的脚本.

How can I replicate the python environment setup of a windows machine onto another computer and be able to run very specific scripts successfully.

我们已经在anaconda环境中使用python 3.6.5编写并运行了脚本,我们希望能够在新的Windows 10计算机上运行这些脚本.

We have scripts that were written and run in python 3.6.5 in the anaconda environment, we want to be able to run these scripts on a new Windows 10 computer.

这些脚本还连接到计算机(Postgres)上的本地数据库.

The scripts also connect to a local database on the computer (Postgres).

推荐答案

由于您使用的是anaconda环境,因此我假设您一直在为您提到的项目使用virtualenv.使用以下代码实际上很容易复制:

Since you are using anaconda environment, i assume that you have been using the virtualenv for the project you mentioned. It is actually easy to replicate with the following codes:

# list all virtualenvs in your anaconda folder
$ conda info –envs          # this will list all virtualenvs created by you, you can then choose the specific virtualenv here.

# to activate the virtualenv of your interest
$ conda activate [virtualenv_name] 

# export all packages used in the specific virtualenv (conda activated) 
$ pip freeze > requirements.txt             # save the output file as requirements.txt

# set up a new conda virtualenv in current or separate machine and install with the requirements.txt
$ conda create --name <env_name> python=3.6.5 --file requirements.txt  

# Please note that occasionally you may need to check requirements.txt if there is any abnormal list of packages. The format should be in either [package==version] or [package].

或者您可以直接创建整个virtualenv.

OR you can create the entire virtualenv directly.

# copy exactly same virtualenv on separate machine

# export all packages used in the specific virtualenv (conda activated), including current python version and virtualenv name
$ conda env export > environment.yml        # save the output file as environment.yml    

# set up a new conda virtualenv in current or separate machine and install with the requirements.txt 
$ conda env create -f environment.yml       # using Conda; to modify "name" in the environment.yml file if to set up own same anaconda/machine

这篇关于在另一台计算机上复制Python环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆