In my Anaconda 2.2 64bit with Python 3.4.3 the following line works well:
import shapely
But the following line:
from shapely.geometry.polygon import Polygon
returns the following error:
OSError: [WinError 126] The specified module could not be found
What am I missing?
EDIT
I tried with iNotebook, idle.exe and Eclipse. They all use Anaconda (the only Python installation on my computer) and they all show the same error.
If I type from shapely.geometry import Polygon in Eclipse, then I click on Polygon, then I press F3, Eclipse is able to open the module C:\Anaconda3\Lib\site-packages\shapely\geometry\polygon.py. So Eclipse is able to find it, but the execution fails.
EDIT 2
I just tried the same import on another computer with similar configuration and it works. The "only" difference between the two computers is that one has Windows 7 (it works) and one has Windows 8 (it doesn't).
I installed Anaconda and a few packages in both the computers following the same old checklist. The computer with Windows 8 can see the package from Eclipse, but can't import it.
I had a similar problem and it was due to the way that I improperly installed shapely (although this was on a Windows 7 machine, not Windows 8). For the initial install under which I couldn't import the geometry sub-module I installed shapely with the command:
pip install shapely
However after reading the documentation here more closely I saw that for Windows an executable installer needed to be used. That installer is a wheel file that needs to be launched by pip as well. So I uninstalled the first version of shapely with:
pip uninstall shapely
Then I launched the installer via the wheel file like this:
pip install your/file/path/Shapely‑1.5.9‑cp27‑none‑win32.whl
Note that you must download the wheel that matches the specs of the version of python that your applying the package to. I have 32-bit (win32) python 2.7 (p27) so the package above was the correct one. Note that the reference to 32 or 64 bit in the file name refers to the version of python, not to the version of windows.
Try with below one, it solved the issue for me (Windows 10):
conda install -c conda-forge shapely
shapely package docs
Try this:
from shapely.geometry import Polygon
That's how the docs list it:
http://toblerity.org/shapely/manual.html#polygons
Don't use anything but Python version 3.7. Download it now!
Then go to PyCharm (that's what I'm using) and open it, then download the file for your specific version (from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely) mine is Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl (this is respectively version 3.7 (37) and Windows (64) as seen above)
Now with your newly downloaded file, copy and paste it into where you are working from in PyCharm's folder location. For me this is: C:\Users\lewis\PycharmProjects\Project1\NewProject
Then you should see the newly copied file in PyCharm itself as well as where you put it.
Now right click the file in PyCharm Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl
and click OPEN IN TERMINAL then type:
pip install Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl
It should say "successful".
Then go into your working area and type:
from shapely.geometry import point
Run it. It should now work for all!
Be in mind that this will ONLY allow for the importing of Shapely in this one environment. So you'll have to copy the Shapely file into new folder locations if you use in other places.
Specs:
Be in mind I am working with a Windows 10, Python interpreter version 37, PyCharm, Virutalenv environment type. Also, make sure in the settings you are indeed in the Python 37 interpreter and not in a conda environment.
Related
I cannot get autocomplete working for OpenCV (Python) on Windows.
According to Abid's instructions here, I pasted the cv2.pyd file in the C:\Python27\Lib\site-packages.
In the Python code, I import as follows:
import cv2.cv as cv
I have also installed numpy, and it created its own folder in site-packages unlike OpenCV (which I've pasted directly into site-packages).
With this setup, the code executes without any problems, even when OpenCV methods are called.
But I have not been able to get autocomplete to work. I have tried to get it to work on Sublime Text 2 (with SublimeCodeIntel) and PyCharm. In both IDEs, autocomplete works for the numpy import, but fails for the OpenCV import.
I'm using OpenCV 2.4.6, and Python 2.7 (32 bit).
Any possible solutions?
The reason it's not working is because you're using a .pyd file, which is essentially the same as a compiled .dll. Autocomplete works by reading the source .py files, which are plain text. Try installing the OpenCV and Intel Math Kernel Library optimized NumPy packages from Christoph Gohlke's Python Extension Packages for Windows repository, which is frequently updated and a must-use resource for anyone who does any kind of scientific Python computing on Windows. Make sure you delete the cv2.pyd and numpy directories from site-packages first. These new packages will install the .py source files needed by the autocomplete engine in Sublime Text.
EDIT
OK, so I wrote the above because it worked well for a bunch of other packages. I'm a Python 3 guy, and I never installed OpenCV from Gohlke because it only has Python 2 bindings. After reading #CrazyCoder's comment below, I booted up Win7, and indeed he's absolutely correct (and I should have realized this before) - since OpenCV is written in C/C++, the only .py file included in the Gohlke package is cv.py, whose entire contents are as follows:
from cv2.cv import *
The rest is contained in cv2.pyd and a bunch of .dlls. The full OpenCV Windows distribution from opencv.org is a 291 MB download, which expands to 3 GB, and the few .py files in there are involved in building OpenCV, and aren't any good for autocomplete purposes. So, unfortunately, I don't know if there's a solution to your problem at the moment. Just keep the docs handy, and perhaps check out OpenCV Computer Vision with Python from Packt/O'Reilly, published in April 2013.
I've had the same issue with PyCharm when building a custom version of OpenCV on windows. Here is what I did to fix it:
OpenCV made a folder in Python site-packages like so:
opencv site-packages
So what you need to do is just add the python-3.9 folder to your interpreter.
File
Settings...
Python interpreter
Three dots icon next to your interpreter -> Show all...
Select your interpreter and click on the "Show paths for selected interpreter" icon
Add the folder inside the cv2 site-packages
Now import the cv2 module normally.
The best way to solve all the problems of OPENCV-PYTHON is by uninstalling it and reinstalling it.
Even I faced the same problem.
I fixed it by:
python -m pip uninstall Opencv-python
Then I reinstalled it by using a lower version. But unfortunately, I did not know the versions of opencv; So by using a small trick you can get it by running:
python -m pip install opencv-python==
and you will get an error similar to this:
ERROR: Could not find a version that satisfies the requirement opencv-python== (from versions: 3.4.0.14, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 3.4.15.55, 3.4.16.57, 3.4.16.59, 3.4.17.61, 3.4.17.63, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48, 4.5.3.56, 4.5.4.58, 4.5.4.60, 4.5.5.62, 4.5.5.64) ERROR: No matching distribution found for opencv-python==
Here you can see all the versions of opencv-python; choose any one (but not the latest as the error occurs due the latest version of opencv-python. install it by using:
pip install opencv-python==3.4.17.61 (You can choose your version, but this version solved the issue for me)
then enjoy your coding....
Even AUTO-COMPLETE error in opencv-python gets solved.
HAPPY CODING
I know this question has been asked many times before but I cannot find a solution that works for me. I'm running Python 3.5.3 under Blender 2.79 in Windows 10. As I require Blender 2.79, upgrading the Python version is not possible.
I've installed matplotlib and I can import it. However, when I try to import pyplot (e.g. import matplotlib.pyplot as plt), I get a crash to desktop with no error messages of any kind. This happens if I run Python externally or from inside Blender. The weird thing is that I was able to avoid this by changing backends to agg (matplotlib.use('agg')) and this is still working in a previous installation (so I know it's possible to get this to work !), but not in a separate, new installation of Blender. I've tried other backends but they make no difference.
The exact procedure I've tried is as follows :
Downloaded Blender 2.79 from a zip file (I'm using Windows 10) and unpacked it (call this directory /Blender/)
In /Blender/2.79/python/bin I run the command ./python -m ensurepip
In /Blender/2.79/python/scripts I run pip3 install --upgrade pip --user. This gives me pip3 version 20.2.4
In the same directory I run pip3 install --target="/Blender/2.79/python/lib/site-packages" matplotlib --upgrade. The "upgrade" switch is to prevent warnings that the "/bin" directory exists. Doesn't make any difference if I remove it, there's no existing installation of matplotlib. This gives me matplotlib version 3.0.3
Finally I start Python by /Blender/2.79/python/bin/python.exe, and do the above mentioned importmatplotlib.pyplot command which causes the crash.
I've tried this from a completely fresh installation of Blender, which comes with no existing external modules installed. Could there be some conflict with other Python modules elsewhere ? How would I go about diagnosing what's going on ?
Thanks for any ideas !
FIXED ! I remembered I found the solution months ago, but stupidly wrote down the answer in the wrong file...
The problem is that matplotlib is looking for a file that doesn't exist. In c:/users/me/.matplotlib (a hidden file), there's a file ""fontlist-vXXX.json", where XXX is the version number. This is set in line 951 of the file "font_manager.py", located in /python/lib/site-packages/matplotlib. In my case, the font_manager was looking for version 300 but the actual file was 310. Changing the version number in the font_manager.py made everything work correctly.
I realize this seems like a generic question, but all answers pointed to having two simultanious python installations - I already uninstalled the other one.
Currently I run my code from PyCharm 2017.1.5 (windows 10) with Python interpreter set as Python 3.6.1 (C:\Anaconda3\python.exe), i.e. I installed Anaconda3, which includes the matplotlib, and run from PyCharm using the Ananconda3-interpreter.
I've checked in Anaconda Navigator that matplotlib 2.0.2 is installed in the environment.
A minimal (non-working) example:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
Returns the following error:
C:\Anaconda3\python.exe C:/Users/John/Documents/CPU/master/untitled/main11.py
Traceback (most recent call last):
File "C:/Users/John/Documents/CPU/master/untitled/main11.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Anaconda3\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Anaconda3\lib\site-packages\matplotlib\collections.py", line 37, in <module>
import matplotlib.lines as mlines
File "C:\Anaconda3\lib\site-packages\matplotlib\lines.py", line 28, in <module>
from matplotlib.markers import MarkerStyle
ModuleNotFoundError: No module named 'matplotlib.markers'
Process finished with exit code 1
This ran fine 2 weeks ago, but not now. To my knowledge, I didn't change or update anything. The module loads correctly, but it seems to be a change in the module content? If so: How did that happen and how can I fix it?
In my case, I could fix it by setting PYTHONPATH to the path to site-packages folder where the needed packages are located, excluding site-pacages.
I use a pyenv virtual environment, whose path is /home/apk/.pyenv/versions/python-3-7-4. When the environment is activated, pip installs packages to /home/apk/.pyenv/versions/python-3-7-4/lib/python3.7/site-packages. Therefore, in terminal, I set:
$ PYTHONPATH=/home/apk/.pyenv/versions/python-3-7-4/lib/python3.7/
The same should be true for Windows installations of python.
If virtual environmets are used, then one could edit activate script to set PYTHONPATH.
After I did it, I checked in a python shell.
$ python
Python 3.7.4 (default, Feb 5 2020, 17:11:33)
[GCC 5.5.0 20171010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/apk/.pyenv/versions/3.7.4/lib/python37.zip', '/home/apk/.pyenv/versions/3.7.4/lib/python3.7', '/home/apk/.pyenv/versions/3.7.4/lib/python3.7/lib-dynload', '/home/apk/.pyenv/versions/python-3-7-4/lib/python3.7']
>>> sys.executable
'/home/apk/.pyenv/versions/python-3-7-4/bin/python'
Good luck!
References
https://github.community/t5/Programming-Help-and-Discussion/Python-ModuleNotFoundError-although-module-is-installed-aiohttp/td-p/28525
#ImportanceOfBeingErnest lead me in the right direction. I post my solution here s.t. others may find the answer. The problem was a corrupted disk sector - an unlikely event of chance.
The problem was indeed in the matplotlib-package itself. Retrospectively, pointers to the issue were that errors in pre-distributed packages should not exist. If they do, external circumstances must have corrupted and the problem is not with the Python-installation itself.
I uninstalled matplotlib through Anaconda Prompt with conda remove matplotlib and re-installed with conda install matplotlib. This gave me this error:
(C:\Anaconda3) C:\Users\John>conda install matplotlib
[...]
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'defaults::matplotlib-2.0.2-np112py36_0'.
OSError(22, 'Invalid argument') Attempting to roll back.
OSError(22, 'Invalid argument')
Before #Ernest's comment, I thought it maybe had to do with non-ASCII in PATH or similar.
Instead I tried to reinstall Anaconda3 completely, restarted and found that part of the Anaconda3-folder weren't removed (the one containing the matplotlib).
Deleting it manually gave a Windows error 0x80070570. Following this post on ServerFault (the comment to OP) I ran a check and afterwards a repair from Windows Explorer GUI: Right-click on the drive in This PC --> Properties --> Tab Tools --> Check (repair appears if any errors are found).
After some restarts, reinstalling Anaconda3 from scratch and restarting again, I was able to run my project again!
It is difficult to answer this question directly, however, I have seen a large amount of issues in corporate Windows environments with PyCharm and Anaconda these are some of the issues you may be having
Check you PATH is correctly pointing to all Anaconda locations
import sys
sys.path
Check that your files have not been migrated to C:\Users\username\AppData\Roaming by your IT team
Purge your system for any python distributions. There may be software distributions that you use internally that package their own python distribution. This can often be included in the PATH. Another example could be installing Anaconda to your C:\ but also having it already installed in Users\Local\AppData or 'C:\Program Files' months before and forgotten!
A good way of directly debugging your problem would be to navigate to the following directory in ipython
C:\Anaconda3\lib\site-packages\matplotlib
and they try import matplotlib.markers
If this fails then you could then try
import matplotlib
matplotlib.__file__
you should check that this result gives
'C:\\Anaconda3\\lib\\site-packages\\matplotlib\\__init__.pyc'
as most likely there will be another matplotlib version installed that is taking precedence. This will then fall under one of the issues above to correct.
Got the same type of error while using pip. created new VENV and execute the app agaist that resolved my issue
PyCharm requires installing packages available in the interpreter.
You can find matplotlib and other packages available for an install using the following steps:
Open the File--Settings--Project--Project Interpreter menu.
You should see all packages you currently have installed, and matplotlib should be missing from this list.
Click the + (add) button to the right and install the matplotlib package.
Once complete, close the top dialog box, and you should see matplotlib in the list of installed packages.
I've been trying to install PyGame with little success. I downloaded the
pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg
version of PyGame from this link and installed it using the wizard, but when I typed import pygame into the IDLE I got the following message.
$ import pygame
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
What did I do wrong?
Also, what are the prerequisites for PyGame? I'm doing all this on a new computer and I've hardly downloaded anything.
I'm running OS X Version 10.8.2.
I know this thread is a little old, but thought I'd share my experience on this subject...
I'm using a 64-bit MacBook Pro running OS Mavericks and python 2.7.
Steps:
If you've installed a few different versions of pygame while trying to get the darn thing to import and work successfully, make sure you delete/uninstall all of these to get a fresh start. I did a simple search in the terminal to see where all of the various pygame folders where located:
In Terminal: sudo find / -iname "pygame"
The results show a list of all the pygame directories, these are the folders that you want to delete. Note, I created a new tab in terminal to do this so I can reference the directories from the search on the previous tab and easily copy each directory without having to do another search to remember where they are:
In Terminal: sudo rm -R -i path/pygame
Also note, you can take the -i out of the above code and it won't confirm the deletion of certain files, but BE REALLY CAREFUL when deleting full directories from the terminal.
Once your machine is clean of all previous pygame installations, make sure you have python 2.7 from python.org, NOT IDLE (default Mac Python Interpreter)! This is very important. I use PyCharm and it rocks! Also, choose the version that works on a 32-bit machine and 64-bit machine - this way you won't have issues with the pygame 32-bit installer on your 64-bit machine. I tried same installation process but with the 64-bit only python 2.7 installation and it didn't work. Link provided below:
Download 32/64-bit Python 2.7
Next, download the 32-bit pygame file for OS X 10.3 and beyond and run the mpkg file created from the dmg. Link provided below.
Download pygame 1.910 release for python 2.7
You should now have a working pygame installation in your python 2.7 package library. Enjoy.
Did you install python from python.org? Or use the one that came with OS X?
If you used the one supplied by Apple, you must download the one from python.org first, then install using that package. Or you can try the Lion-pygame package (the link is at the bottom of the Macintosh section of the download page), but it may be incompatible.
Did you download python 64-bit or python 32-bit?
This can cause major problems if you don't have the right one, if you have 64-bit you can download pygame 64-bit from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.
So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the
import numpy
import pylab
disappeared so I understood that the reference to that module is ok.
Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).
Can anyone tell what should I do to run this code?
my interpreter setting on eclipse:
If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.
Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *
Edit:
Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.
I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.
I first tried adding a reference to the site-libraries at:
C:\Anaconda3\Lib\site-packages
And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:
C:\Users\myname\AppData\Local\Programs\Python\Python35-32
However, Anacondas installed another version somewhere else. By going into:
Windows > Preferences > PyDev > Interpreters > Python Interpreter
and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.
Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.
Simply removed the old numpy and installed version 6. located here
Another way to circumvent this problem is to use pip install numpy check how to install pip