Python – How to run a python script using Anaconda from the command line

command linepython

Note: I'm new to Python and I've never really used external modules like the ones listed below so feel free to let me know if there's anything I could be doing better in order to get my program up and running.

I'm currently working with a python (2.7.x) program that requires the use of the SciPy stack. The previous developer of the program was using Anaconda in order to access all external modules. In my case, I need to be able to run the entire program with a single command. For example:

python myFile.py

Will execute myFile.py (which has the following imports):

from numpy import *
from pylab import *
import matplotlib.pyplot as plt

From what I understand, Anaconda is an IDE that requires you to execute code in a similar way to Visual Studios (i.e. a "Run" button). So my question is:

Is there a way for me to do this directly from the command line?

Note: The reason I'm specifying the use of Anaconda instead of just using the external modules themselves is because on the SciPy website there's constant mention that it's easiest to just use a scientific python distribution like Anaconda or Python(x,y). Ultimately, I'm okay with any solution that allows me to run my program with the above imports.

Best Answer

  1. Create required Anaconda environment conda create --name environmentName python=3 pandas numpy. Include all your dependencies at once while creating the environment.
  2. Switch to the environment with conda activate environmentName.
  3. Executing the python script python fileName.py. You don't have to specify the python version because the script is running inside the Anaconda environment. The version used will be whatever is specified in the environment (the script required python3 which has already been specified in Anaconda environment).
Related Question