Anaconda can’t run Python script in command prompt

anacondaenvironment-variablespippython

I just created a Python script, which is running fine in Spyder (I'm using Anaconda).
When I try to run it now in the command prompt, I always get errors that say that libraries are missing, which are definitely installed. I am also pretty sure, that I'm using the same Python environment (the base environment).

I set the environment variable for Python as follows:

Environment variables

When I open cmd in the directory of my script and type "python my_script.py", I get this error:

C:\Users\xx\Desktop\yy>python my_script.py
Traceback (most recent call last):
  File "my_script.py", line 15, in <module>
    import webdav.client as wc
  File "C:\Users\xx\Anaconda3\lib\site-packages\webdav\client.py", line 3, in <module>
    import pycurl
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

But when I try then to install pycurl, I get this error:

C:\Users\xx\Desktop\yy>pip install pycurl
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Requirement already satisfied: pycurl in c:\users\xx\anaconda3\lib\site-packages (7.43.0.2)

I think there's something wrong with the path variables, because I just had this problem also with numpy. After uninstalling and installing it a few times, the numpy error disappeared.

But like I said, it's really weird that the script runs fine in Spyder, but doesn't work in the command prompt – even though I'm using the same Python environment.

Does anyone know how to fix this issue?

Best Answer

I had a similar issue. similar issue

python my_script.py

in CMD doesn't engage the anaconda environment - even base. In the Scripts directory (the one under your Anaconda3 directory there should be a batch file named activate. Running this batch file prior to running my script solved my issue that had symptoms similar to yours.

I made a batch file to run activate and then run my script as follows:

c:
call C:\Users\RAdams\AppData\Local\Continuum\miniconda3\Scripts\activate base
pythonw C:\Users\RAdams\blahblah\receiving3.pyw
conda deactivate
Related Question