0

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

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.

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

  • This is a good question. There are techniques to clone/save environment state in a file to later "reproduce" it. The reality is, reproduction does not always work, especially on large or old environments. At this time, there is no complete solution, only best practices found in various places. – pylang Sep 06 '21 at 22:49

1 Answers1

2

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].

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
hongkail
  • 679
  • 1
  • 10
  • 17
  • 1
    This answer is largely correct, just keep in mind that your original environment may have many packages installed that aren't actually required by your script. These would still be captured in the `requirements.txt` with this method, so you may be installing more than required. – Grismar Feb 09 '21 at 04:43