Please note that I am a complete beginner and installed python simply by going to the website and clicking "install". It used to work fine.
Now suddenly I have this frustrating situation where I can run just about anything in the idle.exe found in the scripts section of arcgispro, but cannot run the same .py file in an IDE. As a beginner this is obviously a headache as I would like auto code formatting, suggestions, etc. Literally any IDE would be fine (spyder, pycharm). The problem is that every single time there is some kind of error with the package imports. e.g. from pycharm:
import shapefile ModuleNotFoundError: No module named 'shapefile'
It's not just shapefile... this is happened at random times with numpy and also matplotlib.
When I look at "Installed Apps" on windows, it just says Python 3.10.0 and Python Launcher.
No, there is no file that I created called "shapefile.py"
A lot of solutions suggest things with pip... I have absolutely no idea what pip is...is it installed program? where do I find that?
EDIT: I just found out that the system paths of the two are different so this explains why one works but the other doesn't... but how can I make it so that the IDE would work?
Ok, simple answer:
In Pycharm, go to the bottom and click on Python Console. Then type pip install pyshp. Voila! Assuming it works for other packages as well. Still do not know where to make pycharm work with the other environment...
When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm doesn't seem to be aware of their availability. The imports are marked with a grey underline, saying "unresolved reference" as a tooltip, and autocomplete doesn't work, either. (Except for the function names already used in the code.)
This isn't caused by wrong module paths, the code runs without error when started. Also, after I import the modules in a Python shell, autocomplete starts working as expected.
Is there a solution for that or is this an architectural limitation for compiled extensions? Are there any other IDEs that manage to cope with this problem?
The imports are marked with a grey underline, saying "unresolved reference" as a tooltip
This most probably means that PyCharm can't see the module you import. In editing mode, PyCharm relies on availability of Python sources of imported modules. If a module is not written in Python but is a C extension module, PyCharm generates a 'skeleton' that contains function prototypes, and uses it for completion.
In shell mode, PyCharm uses live imported objects for completion, with slightly different results.
Make sure that your OpenCV installation is visible for the Python interpreter you chose for the project (File / Settings / Python interpreter). If the interpreter is correct, try removing and re-adding it (this is time-consuming a bit, sorry).
If nothing helps, file a bug.
I have noticed a difference in pycharm behavior depending on the way to import.
using:
import cv2
the auto completion doesn't work,
while with:
from cv2 import cv2
auto completion works
I had to hardlink the binary into the folder lib-dynload of my interpreter.
$ cd /usr/lib/python3.7/lib-dynload
$ sudo ln /usr/local/lib/python3.7/dist-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so cv2.cpython-37m-x86_64-linux-gnu.so
The paths may vary in your environment. I didn't test it on OSX or Windows, but it may work there too. The lib-dynload folder is here:
PyCharm currently does not scan compiled extensions/binaries which are in a path manually added to the interpreter in the IDE. I have filed a bug with Jetbrains in YouTrack. You might want to have a look at it and possibly the discussion I initiated in their discussion forum (link is in the bug description). I'd appreciate if you could vote for this issue to be resolved in YouTrack if you are a PyCharm user facing the same problem.
Try clicking "Reload" button in File | Settings | IDE Settings | Python interpreters. That got it working for me.
In my case on OS X 10.8 and PyCharm 3, IDE was automatically picking different installations of Python. I noticed this in Eclipse Pydev, which picked up the one right one and worked as expected. It was not easy to notice the difference between the two:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python
I follow the instructions under this question:
How to install OpenCV on Windows and enable it for PyCharm without using the package manager
After that it does not work and I reinstall the pycharm ide without any other changes and now it is working perfectly.
I know that this is not the best answer, but after a lot of time wasted and trying different workarounds this was the one that solve my problem, I hope it can help you.
After two days test,I finally fix this issue:
The difference:
Uninstall python 3.7.2,install python 3.7.7.
Change the path where python install.(I strongly doubt that the cause is that my PATH of opencv-python has some Chinese characters.It should have only English).
Then do:
Install the opencv-contrib-python.
I hate to give a "works for me" answer, but maybe the details on my environment will help you identify the problem on your end.
I've never used PyCharm before, but I just did a test on Mac 10.6.6 using PyCharm 1.1.1, with Macports opencv +python26. The autocomplete worked fine for me the first time. I also closed and re-ran PyCharm and was able to autocomplete without doing anything further. I also had no issue with autocomplete for other native extensions I tried like cjson, procname.
.
Perhaps it is a platform-specific issue (Windows?), or a bug affecting an older version of PyCharm?
In my case, include opencv in the path install-opencv-4-on-windows. and add it to the project settings, if none of this works for you, I recommend that you install anaconda change the python interpreter and use the anaconda interpreter.
for this go to : file -> settings -> project:test -> python interpreter and select conda interpreter
if you dont have anaconda you can download at https://www.anaconda.com/
follow the steps in the link python-opencv to install opencv in anaconda
I have a launchd entry that worked with OSX 10.6 but that fails with 10.7. It uses python, and it produces an error whilst trying to import serial. I don't quite understand this, because I've re-downloaded pyserial-2.5 and re-installed it with sudo. (In desperation, I re-installed it for each of the many flavours of python on my machine.) As a test, I can enter python and do import serial without difficulties. Maybe there is a system path that is set up well for an interactive user, that is not set up for launched??
Can anyone suggest how I might diagnose the problem?
The path you are appending:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
is the site-packages directory for a third-party, non-system Python, possibly installed using a python.org installer, and not that of the Apple-supplied system Python 2.7, which would be:
/Library/Python/2.7/site-packages
So most likely you are using the python.org Python to install pyserial but are launching the system Python under launchd. Check your shell PATH (echo $PATH), it probably has:
/Library/Frameworks/Python.framework/Versions/2.7/bin
in it. And try which python. If you want to use the python.org Python with your launchd plist, modify it to use an absolute path to the right Python, for instance:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
If you want to install pyserial with the system supplied Python, you can use an absolute path to it when doing the install:
/usr/bin/python2.7
Some experimentation with python -S showed me that the sys.path was not set up properly, so I solved the issue by
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages')
import serial
which I know is awkward, since it is so specific, but I guess I'll have to live with that, unless or until I can find a way to tell python where to find things, as it is being invoked from launched.
PS to anyone coming here later: the switch to OSX 10.7 (Lion) changed loads of things. Perhaps I had some initialization file somewhere, that I forgot about. If I find that, I'll try it that way, and post a further comment here.
It seems like my Eclipse PyDev does not recognize that Twisted is installed on my system. I can't make auto suggest working. Does anyone know how to solve it?
go to preferences->Pydev->Interpreter - Python and hit the apply button. That will rescan your modules directory and add any missing modules.
That should fix any normal import errors. Some modules do some runtime magic that PyDev cant follow.
I recently downloaded and installed feedparser with python,
I tried to run it but Netbeans shouts on import:
ImportError: No module named feedparser
restarted the Netbeans, still no go.
Netbeans by default uses Jython,
if you go to Tools>Python Platforms and see that Jython is the default.
Switch it to Python and so the installed libraries would work.
If you already have a project, you should right click on it, choose Python and on the platform choose Python instead of Jython.
You might need to set the PYTHONPATH environment variable to include the install path of feedparser. Just a guess, but this has fixed this issue in the past for me.