Jupyter cant run shapely.geometry - jupyter

Hey so I've managed to get shapely.geometry to run just fine on PyCharm.
But the difficulty here is in getting the import to run on Jupyter notebook.
I have done:
import geopandas as gpd
This returns shapely.geometry doesn't exist.
I think I know how to fix this through downloading the file
"Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl" and doing conda install (that)... but it returned that the channel didnt exist...
So I did:
conda install --add channels https://www.lfd.uci.edu/~gohlke/pythonlibs/
(which is where I got the file from) which worked just fine so I then again did "conda install Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl" but it returned:
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://www.lfd.uci.edu/~gohlke/pythonlibs/win-64/repodata.json>
A simple retry will get you on your way...
Tried that, didnt work. Someone please help. Reminder that I successfully installed shapely with all of its modules working through "pip install Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl" WITHIN Pycharm itself.
EDIT 1
Im following the textbook "Mastering Geospatial Anlsysis with Python" It got me to download the packages:
gdal
geos
shapely
fiona
pyshp
pyproj
rasterio
geopandas
EDIT 2
I dont know what i did but somehow i fixed it... but the thing is, i literally did nothing except take out a shapely file with a long name and kept the one just called "shapely".
If i have files like this
gdal-2.2.2-py36hcebd033_1
instead of this
gdal
Is that the problem?????? because if it is, then i dont know how to get files like that they just either appear or they dont.

Shapely is a wrapper of C++ library called GEOS that is not installed with the wheel. You should go to the page and install that library.
Or perhaps you have Pycharm for python 2 and Jupyter for python 3 (or vice-versa).

Running conda install -c conda-forge geos=3.7.1 worked for me.

Related

Install or import in Python?

I am a beginner in Python, trying to still learn the basics. I am mostly interested in using it for Data Analysis and Visualizations, with packages such as matplotlib.
Most of the examples I see, use the code
"import matplotlib"
or something similar.
But there are also cases when people suggest using pip install the use the package.
So, as a rule of thumb, when should one use import and when should one install through the terminal?
Let's say you want to use some library. Let its name be ABC. ABC has some function, let's say function1.
If you write
import ABC
ABC.function1()
you will get error. Because in your virtual environment python can't find library called ABC. You must install it first using pip install ABC in your terminal. After that same code will work.
You must install library first in order to use it.
There is no thumb rule for using a method to install. You can use any method for installing. Aim is to install so that the library is available when you run the code, else you will get an error.
In Windows, if you want to install a package/library use the following Command on DOS Prompt
python3 -m pip install matplotlib.
To Upgrade the same, use the following Command on DOS Prompt
python3 -m pip install --upgrade matplotlib.
You can install and upgrade the package/libraries through Jupyter too.
Once installed, you need to place the import <library_name> on top of the code in which you want to use that library.

No module named 'psycopg2' Error in Scrapy

When I use
import psycopg2
in Scrapy pipeline.py or spider.py I get the following error
ModuleNotFoundError: No module named 'psycopg2'
I know that the error is not valid, because I am running Django server with postgresql, using same venv which contains psycopg2. And also I can connect to db in a test file and enquiry as well. In addition I can run import psycopg2 in Scrapy shell with no issue. So it has puzzled me that I might be missing something,
I appreciate if someone can help me,
Since it took me hours, here is what I have found.
I tested both in windows and Linux Ubuntu, both had same error.
Apparently this is what is happening:
In windows I had Scrapy installed on Core, and in Ubuntu apparently Scrapy is already wrapped in.
I ran my crawler within venv, and it appeared that actually my Scrapy is not installed correctly in the venve. However, Since Scrapy was already in the PATH it was running from Core, where it was no psycopg2. So the above mentioned errors was actually come from come not venv.
Installing Scrapy looked like was very simple in venv at first. I checked that by trying Scrapy shell and it was running, but it was actually were running from the core again. Make sure that you have Scrapy in your pip freeze list in your venv. This is a link that has explained how to address some issues in installation.
You need to install psycopg2 in your virtualenv, issue the next command
pip install psycopg2

ImportError: No module named sympy

I am getting the following error while trying to run a sympy file in order to contribute to sympy. It is :
ImportError: No module named sympy
I installed the sympy module through pip for both python2.7 and python 3.
Also, isympy is working.
Strangly, when I try to import sympy in python's interactive console in the main sympy directory, no import errors are shown but in some other directory, it shows import errors.
Please help me to download the sympy module in a way that I will be able to run the code.
Thanks.
Importing module in python console of main directory.
Importing module in some other directory.
A likely cause here is that you are using two different Pythons. If you have Python installed multiple times (like Python 2 and Python 3), each has its own separate packages. You can check what Python you are using by printing sys.executable.
I should point out that for the purposes of contributing to SymPy, you generally want to run against the development version. That is, running Python from the SymPy directory and importing the development version from there, without actually installing it.
Thanks for the reply.
But I solved the problem. I realised that I didn't install sympy in the current conda environment. When I tried it using the command:
conda install sympy
It worked and no error is being shown.
Thanks.

Cannot import module in pip freeze list

I cannot import a module that I see in the pip freeze list (in my case django-olwidget, but I don't think it's nothing to do with this module).
With the virtual environment activated, I:
uninstalled an old version of the module (0.47)
confirmed that it is gone from the freeze list
pip installed the module again
checked the module is in the freeze list now (django-olwidget==0.50)
The environment is active but, now I cannot import the module. Any ideas?
I don't know if this question is still relevant, but I had a similar problem which I just asked a question about before realizing the error. See here. TL;DNR need to specify pip version to install packages correctly.
For python 2.7:
pip2.7

How to install specific .egg pieces with easy_install

I am trying to install ZODB on a new machine. I would like to match the same installation I have on another machine (the newest ZODB does not install correctly with easy_install). I have the easy-install.pth from the original that I would like to install on the new machine:
import sys; sys.__plen = len(sys.path)
./zodb3-3.10.0b1-py2.5-win32.egg
./zope.interface-3.8.0-py2.5-win32.egg
./zope.event-3.5.1-py2.5.egg
./zdaemon-2.0.4-py2.5.egg
./zconfig-2.9.0-py2.5.egg
./zc.lockfile-1.0.0-py2.5.egg
./transaction-1.1.1-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
Is there a way install these exact files on the new machine? I tried copying the folders onto the new machine, but python does not see the module.
pip supports a manifest or you can use zc.buildout. pip may be the least friction if you are comfortable with easy_install.
I ended up just copying over the .egg folders over to the new machine as well as the easy-install.pth (which I renamed to zodb.pth) and everything worked great. Not perfect, but exactly what I was looking to do.