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.
Related
I am using Spyder and I am working with a virtual environment created with conda create, which is located in C:/Users/username/.conda/envs/...
To deal with GDAL proj.db error (proj_create_from_database: Cannot find proj.db) I need to set:
os.environ['PROJ_LIB'] = "C:/Users/username/.conda/envs/test/Library/share/proj"
Because I am not writing the script only for me, I would like to write a line to find a path to the current conda environment and save it as 'conda_env_path' variable (in my case C:/Users/username/.conda/envs/test).
All the answers I found say about finding path to environment in anaconda prompt, not as a line of a script. Thank you.
I have uninstalled a couple of installations of Python from my Windows 10 machine, but when I try to run pip from the command prompt now, using the only python install that is specified in PATH in the System Environment Variables, it gives me this error:
Fatal error in launcher: Unable to create process using '"c:\programs files\python37\python.exe" "<other correct path that exists and is in the PATH variable>pip.exe"
This is happening regardless of whether I specify a package to install or not. I think there is some confusion over this old python37 install which no longer exists. Where can I find and remove any reference to this path which does not exist on disk?
Thank you,
Adnan
Try removing Python from your computer, then removing variables from PATH manually via System Properties > Advanced > Environment Variables (this link can help how to find it). Also, remember that
(...) there are two sections, User Variables for Current User, and System Variables.
Delete Python references from both sections, then reinstall the version of Python that you need, with Add Python 3.x to PATH option checked.
I have an existing vanilla Python installed on my Windows 10 computer and I do not want to reinstall Anaconda.
When trying to run code from ipynb file in vscode, I get the following error:
Error: Jupyter cannot be started. Error attempting to locate jupyter:
at A.startServer (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:786120)
at async A.ensureServerAndNotebookImpl (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:785575)
at async A.ensureServerAndNotebook (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:785376)
at async A.submitCode (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:1:782328)
at async A.reexecuteCell (c:\Users\[username]\.vscode\extensions\ms-python.python-2020.2.64397\out\client\extension.js:75:879318)
Also with the following error from VSCode:
Below are some of the things I have tried:
Check if the VSCode Extension in Correctly Installed
"Jupyter" extensions is deprecated. I had the "Python" plugin from Microsoft installed which contained Jupiter Notebook support.
Jupyter Installed Correctly
I tried reinstalling jupyter:
> python -m pip install --upgrade pip
> pip install jupyter
> pip install notebook
Tried to Run Jupyter on Terminal/Command Line
> jupyter notebook //didn't work
jupyter : The term 'jupyter' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ jupyter
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (jupyter:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
This gave an error not able to find jupyter executable.
According to this post I tried the following and it worked:
> python -m notebook
Check if pointing to the right interpreter
As per this post I tried:
Press Command+Shift+P to open a new command pallete
Type >Python: Select Intepreter to start jupyter notebook server
But I only had one version of Python installed on my computer, and doing this didn't make a difference.
Check the Path
There was this comment about PYTHONPATH in this post but since the python directory is correctly referenced and python works from the command line, I did not investigate it further.
One thing to note is pip installs to my "C:/Users/[username]/appdata/Roaming/Python-38/" folder while my Python is installed in "C:\Program Files\Python38-32\".
If you are having similar issues, please try the above steps mentioned in the question.
After reading this article I realised that I had to map the scripts installed with pip as well, even if it is in my roaming directory. https://discuss.python.org/t/windows-appdata-roaming-vs-local/2682. A confusion that costed me so many hours.
Here are the steps to add the variable:
Go to environmental variables (if you don't know how, here is some instructions: https://www.techjunkie.com/environment-variables-windows-10/)
In the "User variables for [username]" section, Edit "PATH" variable. (it can't be System variables section because only you will have access to your own roaming folder)
Add "C:\Users[username]\AppData\Roaming\Python\Python38\Scripts" (or where the pip installs the scripts to to the PATH variable.
Finally restart VSCode for the new environmental variable to be updated for VSCode.
Now run the scripts in the ipynb file and it should work. It may also complain that it needs other modules, in which case you can use 'pip' to install it.
NB: if you are not constrained by having an existing python version on your computer and not wanting to install more, you can also use the Python Anaconda Distribution. https://www.anaconda.com/distribution/
NB: if you want jupyter note to work for all users using your computer, you need to configure pip to download installs to a directory that is not in your "C:\Users[username]" folder, and add a System variable to it.
For me, another solution helped. I'm not quite sure, what was the issue though, but somehow the state stored for the exact workspace made Python extension crash.
VSCode stores the states for all the workspaces, in its global config folder under /Code/User/workspaceStorage/. See the path to the settings.json in this help paragraph for your OS and then just replace the end of the path. For Windows, for example, the settings path is %APPDATA%\Code\User\settings.json, so the state storage is
%APPDATA%/Code/User/workspaceStorage/
In this directory, there are many subdirectories with some hex names, which are hard to relate to the workspaces. To find out the id of the workspace
Open it in VSCode
Help → Toggle Developer Tools
In Console tab there execute the following to get the workspace id:
vscode.context.configuration()["workspace"]["id"]
Then you can delete the workspaceStorage subfolder by the id of the workspaces.
Another approach is by using the workspaceStorage folder contents themselves. Each of this folder contains a workspace.json which usually includes the path to the workspace. So I wrote a little python script to help me browse them. At the end of the script, there is a draft on removing all the workspaces for the remote containers. Feel free to modify it according to your needs.
from glob import glob
import os, json, sys
from shutil import rmtree
if sys.platform.startswith("win32"): path = os.environ["APPDATA"] + '/Code/User/workspaceStorage/' # Windows
elif sys.platform.startswith("darwin"): path = os.environ["HOME"] + '/Library/Application Support/Code/User/workspaceStorage/' # Mac OS
elif sys.platform.startswith("linux"): path = os.environ["HOME"] + '/.config/Code/User/workspaceStorage/' # Linux
for f in glob(path + "*/*.json"):
with open(f) as fr:
ws = json.load(fr)
d = ""
if "folder" in ws.keys():
d = ws["folder"]
elif "workspace" in ws.keys():
d = ws["workspace"]
elif "configuration" in ws.keys():
d = ws["configuration"]["fsPath"]
ws_path = os.path.dirname(f)
print(d, ws_path)
if d.startswith("vscode-remote://attached-container") or d.startswith("vscode-remote://dev-container"):
print("Inside a container")
# rmtree(ws_path)
When i try run code into Jupyter notebook i getting Import error(attached image).
I add paths to PYTHON_PATH and add %PYTHON_PATH% in system PATH, but i still get thos error
If you are using Anaconda, you must know that it ignores PYTHONPATH!. Use the following commands:
conda develop ~/models/research/
conda develop ~/models/research/slim/
here is why you need to do it in this way. When you issue the above commands, it will create a .pth file inside your current's environment site-packages folder. Then, adds those two paths to this .pth file. Then, whenever you load your Anaconda prompt, those are on the path. This works for both Linux and Windows.
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.