Using standalone EDM (Enthought Deployment Manager), or Canopy v2 (which includes an embedded EDM), you can create multiple Python environments. These environments can contain different Python versions, different package collections, and/or different package versions. For information about creating such environments, see:
When you have multiple environments, you need to take care in specifying which environment to use. This article describes several ways that you can do this from a command prompt / terminal. (To do this in the Canopy GUI, see the above-linked section in the Canopy User Guide).
In this article, we will assume that you have created a Python environment named testprod, and that you wish to run myscript.py in that environment. We describe four different ways to do this.
Use edm's machinery to locate and use the environment
A) Start a new child shell with testprod as its default Python; then run the script there:
edm shell -e testprod python myscript.py exit
(Because this starts a child shell, you use the exit command when you are finished. This returns you to the parent shell where you were before typing the edm shell command.)
or B) Run the script directly:
edm run -e testprod -- python myscript.py
Specifying the location of the environment explicitly
You'll need to know the parent directory of your testprod environment. We'll refer to this directory as <path-to-envs>
. If you don't know it, you can discover it with this command:
edm envs list
C) Activate testprod to be the default Python in the current shell, then run the script:
Windows:
C:\<path-to-envs>\testprod\Scripts\activate.bat python myscript.py deactivate
Mac or Linux:
source /<path-to-envs>/testprod/bin/activate python myscript.py deactivate
(Because this modifies the environment within the current shell, use the deactivate command (not exit) when you are finished. This resets the environment to where it was before activate.)
or D) Run the script directly:
Windows:
C:\<path-to-envs>\testprod\python.exe myscript.py
Mac or Linux:
source /<path-to-envs>/testprod/bin/python myscript.py
Please do not enter support requests in article comments
Please use article comments for suggestions to improve the article. For individual support requests, please follow these guidelines.
Comments