简体   繁体   中英

numpy missing when running python in CMD (python installed with anaconda)

I want to run a locally stored .py program in the CMD line of windows because it is the only way I can call the programs from other programing enviroment.

When trying to do so I specify in the CMD line the location of python.exe (anaconda folders) and the location of the python program.

The problem is that whereas the programs work well when run in the anaconda environement (jupyter started from anaconda) they are missing the libraries installed in anaconda (the ones not included in the basic library, pandas numpy).

I find in here exactly this same problem but trying to implement the solution proposed does not solve the problem in my case.

Situation: Python 3.7 installed in Windows machine with anaconda. Pandas and numpy present in the list of installed packages in the anaconda navigator. Pandas imported with no problem into the jupyter notebook with no problem.

Program writen in Jupyter notebook started from anaconda navigator.

Download .py file in a particular location of the hard disc.

Open CMD terminal and run

C:\Users\xxxxxx>C:\Users\xxxxxx\AppData\Local\Continuum\anaconda3\python.exe C:\Users\xxxxxx\pyCODE\pySoft.py 

Traceback (most recent call last):

 File "C:\Users\xxxxxx\pyCODE\pySoft.py", line 30, in <module> import pandas as pd

 ModuleNotFoundError: No module named 'pandas'

Following instructions in the above mentioned link I unstalled pandas and numpy in the anaconda prompt line

(base) C:\Users\xxxxxx>pip uninstall pandas

In principle the pandas should be uninstalled.

surprisingly enough the pandas package can still be found in the enviroments anaconda navigator (also after close and open), and the jupyter version works (importing pandas does not give error)

if I go again to the anaconda prompt and type:

pip uninstall pandas

the message is: Skipping pandas as it is not installed.

So what is going on here? where is and where is not installed pandas? And above all what are the steps to run a pyhton program from

Btw, i tried to follow this instructions to run from CMD

thanks a lot

(xxxxxx for privacy reasons ofuscated)

In the case that you are using windows 10 you can also set environmental variables for your account even if you are no admin as explained here .

If you want to start the python code via anaconda in the cmd line you could use

set root=C:\ProgramData\Anaconda3\
call %root%\Scripts\activate.bat %root%
python yourcode.py

just make sure that the root directory matches your path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM