Reigndeer
Reigndeer

Reputation: 11

Not able to import geopandas after installation with anaconda

I am trying to install geopandas on a clean environment using anaconda (Windows 10). This has worked properly in the past, but I encountered an error after reverting my base environment (where it was installed at the time) using conda install --revision. I have completely uninstalled and reinstalled anaconda since then, so I don't know how this could cause the problem.

I have followed the instructions from https://geopandas.org/install.html#installing-with-anaconda-conda and have tried both methods of installation using conda. The installation seems to run properly and there are no errors. When I then try to run import geopandas as gpd I get the following error: ModuleNotFoundError: No module named 'geopandas'. I also checked print('geopandas' in sys.modules) which returns False. However, when I run conda install geopandas again I get the following message:

Collecting package metadata (current_repodata.json): done
Solving environment: done
All requested packages already installed.

When I run conda remove geopandas, a bunch of files are uninstalled, implying that they were in fact installed in the first place. I tried several suggestions made to similar posts with no luck. conda config --env --set channel_priority strict, conda update -n base -c defaults conda, even reinstalling spyder. I am currently using python 3.8, but the problem was not resolved when I tried a python 3.7.3 environment, which I know has worked for me in the past.

I know there are other ways to install geopandas, but I want to fix any possible issues with anaconda.

Edit: Spelling errors. More clarifying title.

Upvotes: 0

Views: 2099

Answers (1)

Reigndeer
Reigndeer

Reputation: 11

SOLUTION: The problem was that sys.path did not include the correct path for finding the geopandas package. I ran print(sys.path) and noticed it did not point to my chosen environment. All paths listed were on the form:

C:\\Users\\...\\Anaconda3\\lib\\site-packages\\Pythonwin

when the geopandas package was installed within the environment (testenv) as such:

C:\Users\...\anaconda3\envs\testenv\Lib\site-packages\geopandas

I added the appropriate path to sys.path by running the line:

sys.path.append(r'C:\Users\...\anaconda3\envs\testenv\Lib\site-packages')

This worked and I can now run geopandas properly. I am currently working on permanently adding the environment path to sys.path so I won't have to do this every time.

Upvotes: 1

Related Questions