I have a python script which is running successfully when i run it from spyder. But the same script gives "ImportError: No module named pandas" when run from windows command prompt.
This Q&A mentioned similar problem https://stackoverflow.com/a/10741803/5088142
Can you please check which folders are mentioned in Spyder Tools/PYTHONPATH manager?
Also you can execute the following two lines in Spyder, and identify the location of pandas library:
import pandas
print pandas.__file__
The output should be the path to pandas module
Please add this path to Windows path (reference https://docs.python.org/2/using/windows.html)
Python:
import sys
sys.path.append('_location_of_python_lib_')
Windows CMD:
set PYTHONPATH=%PYTHONPATH%;C:\_location_of_python_lib_
Windows:
Simply add this path to your PYTHONPATH environment variable. To do this, go to Control Panel / System / Advanced / Environment variable, and in the "User variables" sections, check if you already have PYTHONPATH. If yes, select it and click "Edit", if not, click "New" to add it.
Paths in PYTHONPATH should be separated with ";".
The following link show you how to set environment variable in Windows 7 permanently
http://www.nextofwindows.com/how-to-addedit-environment-variables-in-windows-7
You should then install pandas using the windows interpreter.
Open Windows command prompt and type:
pip install pandas
or
easy_install pandas
depending on which package manager you use.
Related
I want to run a python script with the cherrypy module. I use pip install cherrypy to install it and all looks ok. Then I click the "Run python file" button and I face the error ModuleNotFoundError: No module named 'cherrypy'.
Trying to reinstall cherrypy I see many Requirement already satisfied responses.
If it helps I have already edit, in the user path variables panel, the Path variable and added C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts as a path.
edit: I suspect some problem with the path. So i run the following.
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
it returns: 'C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0'
Have you tried to install cherrypy using C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts\pip install cherrypy
When I install py libraries I always run where python and find the right python copy it and modify the path so it goes in Scripts then run pip install cherrypy
Also I noticed that when I install py libraries it seems VSCode won't recognize it even though it runs. To fix this you have to restart VSCode again
Another possibility is that your VSCode isn't using correct version of Python. To check this look at VSCode bottom left you should see your python version. If VSCode can't recognize it you will have to enter the Python path manually by Open Command Palette Ctrl+Shift+P and choose Python: Select Interpreter then click enter Interpreter path
I installed python virtual env. I use vs code. I imported scrapy in my code and vs code doesn't recognize the module. Actually, it works well when I run it. scrapy crawl tester
Just, vs code shows red underlines that mean "Unable to import scrapy" So this is just vs code issue, not venv or scrapy package install issue.
This code works well and actuallay, scrapy is imported without any issue. This is just vs code issue. Thank you.
You might be able to solve your problem by using CTRL+Shift+P to add "Python: Select Interpreter" to your project.
If you created a virtual environment and activated it as well
type which python on macOS/Linux,
type where python on Windows,
inside the activated terminal session.
(env) userpc#pc:~$ which python
/home/userpc/Desktop/foldername/env/bin/python
In VSCode press Ctrl+Shift+P, under >Select Interpreter paste the location you receive using the former command.
Once done, restart VSCode.
VSCode will also ask you to install pylint in your environment and if it doesn't you can do the same by activating you environment and typing
pip install pylint
inside the activated terminal session.
Ran into the same problem - selected the correct Python interpreter in VS Code, pip installed all the desired Python libraries but import is still underlined in VS Code.
What you need to do
What worked for me is to make sure that the linter that you are using in this VS Code instance (I was using pylint) is from the bin folder of the virtual environment, not somewhere else.
How you can do it
I'll use the absolute path to the desired virtual environment /User/ProjectFolder/env as an example.
To check that you meet the conditions stated in What you need to do, toggle the settings.json file in VS Code by pressing ⌘ + ,:
Make sure that the correct Python interpreter is selected. i.e. "python.pythonPath":/User/ProjectFolder/env/bin/python3.
Make sure that the linter (e.g. pylint) is located in that bin folder, not anywhere else. i.e "python.linting.pylintPath":/User/ProjectFolder/env/bin/pylint, NOT something like "python.linting.pylintPath":/usr/local/bin/pylint.
This means that you have to install your desired linter in the virtual environment.
Hope this helps.
I tried #cleon-w's answer which worked for me. (Thanks Cleon)
I was using pyenv on my Mac M1 (Big Sur) with vscode. vscode could not resolve the
paths to python that the pyenv provides, so I looked within the pyenv scripts to find the absolute paths
to the underlying python and the pylint files.
As #Cleon W says I ensured pylint and python are in the same bin directory.
Then edit VS Code settings.json to point to them directly (bypass .pyenv) and the imports could be found.
settings.json (vscode)
"python.defaultInterpreterPath": "/Users/USERNAME/.pyenv/shims/python",
"python.pythonPath": "/Users/USERNAME/.pyenv/versions/3.9.1/bin/python",
I have similar problem with Django. What solved my problem was:
create .vscode/settings.json file inside root dir for project.
add this json {"python.defaultInterpreterPath": "path to bin directory in root dir for project"}
Ctrl-Shif-P -> Python: Select Interpreter -> select one that said: Use Python from python.defaultInterpreterPath. If it's not in the list, hit refresh (circled refresh button on the top of settings box).
I trying to run a program in python 3 that uses numpy but it gives me the error ModuleNotFoundError: No module named 'numpy'. I am using Windows 10. I tried running pip install numpy and it says pip is not a recognized command
You need to add python to your environment variables
Computer -> System Properties (or Win+Break) -> Advanced System Settings
Click the Environment variables button (in the Advanced tab)
Edit PATH and append ;C:\Python27 to the end (if you need substitute your Python version)
Click OK. Note that changes to the PATH are only reflected in command prompts opened after the change took place.
If you are running python 3.6 you will need to add python to your environment path through command prompt
Windows allows environment variables to be configured permanently at both the User level and the System level, or temporarily in a command prompt.
To temporarily set environment variables, open Command Prompt and use the set command:
set PATH=C:\Program Files\Python 3.6;%PATH%
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
These changes will apply to any further commands executed in that console and will be inherited by any applications started from the console.
To change System variables, you need non-restricted access to your machine (i.e. Administrator rights).
If you were to run python -v it should now work
This came directly from the python documents section 3.3.1
Now after you restart you should be able to access python through the command line. If you are running 2.7.9+ or 3.4+ pip will come prepackaged with python. However, if you are running an earlier version of python
Per https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip:
Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt:
python get-pip.py
You possibly need an administrator command prompt to do this. Follow Start a Command Prompt as an Administrator (Microsoft TechNet).
Thanks to How do I install pip on Windows?
Add "way to folder with your python interpreter" and "way to folder with your python interpreter"\Scripts\ to PATH variable. Computer -> Properties -> Extra options -> Environment variables.
This question might be repeat but I did not get answer.
I have write flowing code in python ide .
out_srs = osr.SpatialReference()
**self.out_srs.ImportFromEPSG(4326)**
It run fine but when i run it from application it cause an error as follows
Note - Error in line enclosed in 2 stars -----
"Unable to load EPSG support gcs.csv file check setting GDAL_DATA environment variable which point to gdal library contains EPSG.csv file"
I have done it but i still get this error. but this code run separately but not in application. This code is from gdal2tile module of gdal. i am using python 2.7.6 and gdal 1.10.0 I am unable to sort out what is the problem and where it is. Please suggest how to solve this.
GDAL needs an environment variable named GDAL_DATA that points to a directory with various data files, including gcs.csv. Learn more about it here.
To check if GDAL_DATA is set, and contains gcs.csv, and if this is readable, use the following snippets to check the application. This should be near the code that raises the error.
import os
import stat
gdal_data = os.environ['GDAL_DATA']
print('is dir: ' + str(os.path.isdir(gdal_data)))
gcs_csv = os.path.join(gdal_data, 'gcs.csv')
print('is file: ' + str(os.path.isfile(gcs_csv)))
st = os.stat(gcs_csv)
print('is readable: ' + str(bool(st.st_mode & stat.S_IRGRP)))
Anaconda / Miniconda users
The correct way to use either Anaconda or Miniconda is to activate an environment where GDAL is installed. For example, activate the base environment for Anaconda from Windows cmd.exe:
call %LOCALAPPDATA%\Continuum\anaconda3\Scripts\activate.bat base
Activating an environment triggers environment variables such as GDAL_DATA (and others) to be set, and often changes the command prompt prefix showing the environment name. These environment variables are unset/restored when the environment is deactivated.
conda deactivate
I was able to solve this issue by taking the following steps to set the GDAL_DATA variable in windows.
Find the folder where gdal data is stored
\Anaconda2\envs\gdaltest\Library\share\gdal
open windows command prompt and run following command with the location of your gdal data folder.
set GDAL_DATA=....\....\Library\share\gdal
Happened to me on MacOS Catalina (10.15.5) while playing with PyQGIS (QGIS 3.12). Just searched on Mac finder for gcs.csv which returned multiple results:
/usr/local/Cellar/gdal/2.4.2_4/share/gdal/gcs.csv
/Library/Frameworks/UnixImageIO.framework/Versions/F/Resources/epsg_csv/gcs.csv
/Library/Frameworks/GDAL.framework/Versions/2.2/Resources/gdal/gcs.csv
I stick with GDAL.Framework and just added this environment variable into my script:
import os
os.environ['GDAL_DATA'] = '/Library/Frameworks/GDAL.framework/Versions/2.2/Resources/gdal/'
Script is not complaining anymore.
I've been using ipython notebook with console2 for a while now and recently installed a different version of python and now my console is giving me an error saying "No module named IPython". I think the path has been changed or something, but I don't know how to fix it. Any help is greatly appreciated!
I am pulling the answer out of the comments.
Point your PATH system variable to the correct version of Python. This is accomplished (on Windows) by going to System Properties -> Advanced -> Environment Variables. If you already have a Python directory in there, modify it to the correct, new path. Otherwise, append it to the end of the existing string. Do not remove what is already present.
If you are using anaconda for python the ipython installation is on "Scripts" folder
To get the console2 running with ipython you all have to do to start cmd in silent mode by configuring a new tab in the console2 settings window on win7
here is my config for the shell:
cmd.exe /k C:\Anaconda\python.exe "C:\Anaconda\Scripts/ipython-script.py"
for the startup dir i have just defined the workspace i am using:
D:\python-workspace