1

I have a script that executes without error using Spyder. The same script results in errors when run from command prompt. I don't know why I get the errors. I spent most of yesterday trying to understand why I get the errors and I failed. So I am here.

At line 9 in my script I have

import numpy
import pandas
import pyodbc

the remainder of the code runs odbc queries, manipulates the query results and saves the manipulated query results someplace else.

My script runs without error in Spyder.

I tried to execute the script at the command prompt running as administrator using the code below (I substituted path for the "C:\Users\RAdams\AppData\ etc"):

C:\path\pythonw.exe C:\path\receiving3.pyw 1>stdout.txt 2>stderr.txt

After executing, "stdout.txt" is blank and "stderr.txt" contains:

Traceback (most recent call last):
  File "C:\path\receiving3.pyw", line 9, in <module>
    import numpy
  File "C:\path\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\path\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.

Any idea why this would run in Spyder but not in command prompt? Should I be using something besides command prompt? My goal is to have this run in Windows Task Scheduler - I thought having it successfully run in command prompt would be appropriate precursor.

Also: Yesterday I re-installed miniconda. Using conda I then installed jupyter, matplotlib, numpy, openpyxl, pandas, pyodbc, scikit-learn, seaborn, and spyder into base. I have not created any environments.

2

I created a .bat file with

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

Using the activate.bat file in miniconda3/scripts lets me use the environment numpy was created in (which I assume is why numpy wouldn't work before).

Everything works now - yay!

|improve this answer|||||
0

first solution is to try running it in Anaconda Prompt if you've installed Spyder through Anaconda. If that does not work, try changing the code location(target file) by {cd C:\path}

then run the code normally.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.