Python import not found after VSCode restart - python

My Python import could not be found after i changed the directory and restarted VSCode.
I installed the package via cmd (pip install ) and it was found in Vscode.
I restarted VSCode because i changed the file location to a other directory. The package wasnt found since then. I uninstalled the package and installed it via Powershell but it wouldnt work. Updated the pip installer.
Created a new file with in the directory where it has been before and installed the package again.
VSCode doesnt recognize the package anymore.
Import "" could not be Resolved (Pylance(reportMissingImports))
Does anybody know why this behavious appears and how to fix it?
I havent found a proper solution on here or another forum

In the bottom right of your VS code instance, you'll see something like 3.11.0 64-bit, which indicates the version of Python that VS code is referring to when running and linting your code. The problem is you installed the package with a different version of Python. If you click on the aforementioned button (that says 3.11.0 64-bit) you should see a list of options show up for the different Python versions installed. You need to change to the one that you installed the package on.

Related

Pycharm "Cannot find reference" when OpenCV is in a venv python 3.10

EDIT- Things I tried
*This question is the same, but the solutions there did not solve my problem. I didn't have a DLLs folder so I made one, tried both with and without deleting the file in site-packages/cv2/
*I checked this and this and couldn't make it work.
*I also tried to delete opencv-python from my base interpreter and only download it on the venv, but still didn't work.
*I also tried to invalidate cache/ restart multiple times.
*I also tried to delete python and pycharm completely. When I upgraded to 3.10 I couldn't even install opencv. When I tried 3.8 again the same problem accoured.
I wanted to download ML libraries to Pycharm (python 3.8). Initially I just added them (e.g. opencv-python) in the python interpreter itself (Settings > Project > Python interpreter) and it worked fine (So now my regular interpreter has a bunch of libraries on it).
Then I read it's better practice to make a new venv and download the libraries there. I created a new environment:
Then I entered the new interpreter and added opencv-python (plus sign > searched for this > Install package):
After that I made a short script that needs cv2. Pycharm couldn't import cv2, but the script runs correctly (displays the image) when "run" is pressed.
If I switch interpreter to the regular one it recognizes the cv2 methods and autocomplete me.
I solved it using anaconda.
The first time I tried it didn't work, so it's probably a problem with having non-ascii username (again). I had the .conda folder in a path which contained non-ascii, as well as the anaconda3 itself installed in a different place
To install it correctly:
Uninstall both anaconda, pycharm (uninstall other pythons if you have them).
2. Create a new user with ascii only (e.g. Ben).
In this user:
Install anaconda (I guess miniconda will work too)
Create a venv (I used this and this tutorials)
Install your packages using conda-forge like in the tutorials

PyCharm error - No module named 'sip' (PyQt4)

OK, so I need to make a project in PyQt, and I'm using PyQt4 since I found more tutorials on this and it is easier for me.
I installed PyCharm as my IDE. I haven't had any python compilers so I installed Python 3.7.5 (from Microsoft Store since PyCharm recommended that), and configured the interpreter in PyCharm (so now, python works)
Then, I needed to install PyQt4, and since it didn't work from PyCharm's project interpreter -> install package, I downloaded "PyQt4-4.11.4-cp37-cp37m-win_amd64" and installed it with pip.
Then, I installed sip also with pip.
The thing is that I get an error in my code in PyCharm.
from PyQt4 import QtGui
ModuleNotFoundError: No module named 'sip'
I also configured all my Windows PATHs, when I installed sip it gave me an error saying that the path isn't added. I added that path.
I also added the pyqt4 path.
These are my paths:
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sipbuild
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages
'C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts
And these are all the packages I think I have installed in PyCharm:
Do you know what I can do? I really don't want to use PyQt5 since I know a found tutorials on exactly what I want to do on PyQt4 and I don't really have time to learn PyQt5 now...
I also tried to see if Python 3.7.5 Shell (IDLE) will raise an error, and yes, it did. I have the same error in Python's IDLE.
What is the problem? It worked for a while until I deleted Python a few weeks ago, but now it doesn't work anymore.
Thanks a lot!
I have recently faced such issues, so my recommendations are:
It's good to activate your virtual env for your project.
Usually pip should install the required binaries, but if it doesn't, try searching the same from pycharm -> settings and add directly from there. This has always worked for me.
P.S. I was not able to add comment, so I posted it as answer.

Intellisense not working for python

Intellisense and Snippets for Python are not working after installing python by donjayamanne's extension (ext install python) on vscode 1.8.1. Even pressing ctr+space, it just keeps "Loading..." and nothing happens.
I just just installed this new arch Linux with python-3.6 and new kernel's version. And once VSCode version 1.8.1 finished installing, I installed this extension, then Intellisense and Snippets for python stopped working, however they were working fine last week on the old version of Arch Linux.
I tried many things, I uninstalled both vscode and the extension many times, I changed the path as said here , and now I removed the current kernel (4.8) and installed 4.4-lts, yet nothing happened.
I thought of asking here before I go here to report an issue.
Good news! The owner of the extension updated it and now it's good and working for python-3.6. Just install the new update.

How do I change the kernel/python version for iPython?

I have installed iPython using pip in OS X 10.10, and it gave me the "ipython" and "ipython2" commands, which run great, but which use OS X's default python version 2.7.9. I downloaded and installed the latest release of Python3.4 and can load it with the command "python3," but cannot find a way to get iPython to use this version of python. The iPython Web site states the package can be used with python versions 3.3 and above, but I cannot find any instruction on how to change the default python version used.
So far I have found that the jupyter package for iPython has a kernel specification in /usr/local/share/jupyter/kernels/, which is just a folder called "python2" containing a json file that points to the system's python 2.7.6, but altering this to point to the new python3.4 installation does not work. My guess is this configuration is for the ipython notebook.
I've also tried the approach here: ipython reads wrong python version
In doing so I've duplicated the ipython2 command in /user/local/bin/ and edited it to use the python3 interpreter located at /Library/Frameworks/Python.framework/Versions/3.4/bin/python3, however, this gives me an error "ImportError: No module named 'IPython'," which suggests the python3 installation does not have ipython installed.
To tackle this, I've tried uninstalling ipython and reinstalling it using pip, but it just targets the system's Python 2.7 installation and does nothing for python3.
Does anyone know how to configure iPython to use a different python version, or even install a separate ipython installation for python3? Ultimately it would be nice to quickly switch back and forth depending on my needs.
I just found the answer. In essence, this stems from not understanding the python installation layout and how resources are separated between installed interpreters. It appears each python version will have its own repository of tools, and the current "pip" command I had installed on the system was mapped for use with python 2.7, so all libraries, tools, and other details it managed where available only to python 2.7. This included iPython.
I thought that installing python3 would make all these libraries available to the new interpreter by default, but it appears the system keeps them all separate (which makes sense). The main issue here was continuing to use "pip" which targeted the old installation, instead of the new "pip3" command included with python3. By using pip3 to reinstall iPython, I was able to get iPython3 installed properly.
Unfortunately this setup means needing to re-download other libraries, but that's not too difficult.
It might seem like a trivial issue in hindsight, but this had me completely stuck. I hope this helps someone else in this situation.

Problems in fully uninstalling Python 2.7 from Windows 7

some months ago, I installed Python 2.7 on my laptop (my os is Windows 7).
After, I decided to use Python xy 2.7.3 instead of 'pure' Python; so, as suggested, I removed Python 2.7 and tried to install Python xy 2.7.3. However, when I tried to run the .exe file for installation, a warning window appears telling me that Python 2.7 is already installed on my computer. I tried to install a different version of Python xy (2.6) and everything went fine; however, I'd really prefer to use the latest version of Python xy.
Actually, I can't figure out what went wrong whie uninstalling Python 2.7; does someone have any clue?
I can tell you that I followed the 'normal' procedure for programm uninstalltion; control panel -> Programs -> Remove Program
Thanks in advance
Stefano
Run regedit, backup and delete the registry keys:
HKEY_LOCAL_MACHINE\Software\Python\
HKEY_CURRENT_USER\Software\Python
My problem occurred when changing from Canopy to Python(x,y).
So, also delete all folders that are left behind when uninstalling.
https://support.enthought.com/entries/23580651-Uninstalling-Canopy
I also had this issue as well. It was due to third party installs. Even though you have uninstalled python, it leaves all the third party libraries that were installed and I think Python(x,y) just detects the directory.
To fix, uninstall Python 2.7 and then check to see if C:\Python27 still exists. If it does, go ahead and delete and then try installing Python(x,y). That is what worked for me.
I faced this issue: I tried to uninstall the python and fresh install, reason my pip version issue was not getting resolved. So I deleted the python folder, removed python from system path, and when I tried to uninstall from "Uninstall a program" in control panel, it showed "Windows installation package" error window and could not clean uninstall.
Solution what i found was: In the "Uninstall a program" select python and click repair. And then uninstall the python, it worked for me. Hope this helps and save some time.
PS: I am pretty new to python, and any help correcting me would be appreciated.
Maybe to put an answer out there.
Uninstalling anything from windows can have multiple side effects residing completly on your specific machine. As to what is common:
-> Python sets itself in your windows path. Here is how to modify your windows path: http://www.computerhope.com/issues/ch000549.htm
It means that there is a probability that python is gone but the path entry might not be. That is a guess however -> more information needed
-> Are you sure that everything was removed from your computer? If you already did the normal uninstalling process - try to look up if any python directory is still present.
-> Thirdparty installed? Have you downloaded any libs that are still on your machine.
Besides from that - it could be anything - the more information you give us the more we can say about it.
Maybe this post will help you: How to completely remove Python from a Windows machine?
I had python 2.7.12 and wanted to uninstall it for 2.7.9. I had the same problem as you and to fix it I tried to delete all of the local files and then uninstall however it still gave me the same error. So instead I decided to repair the python 2.7.12 and then uninstall which worked perfectly and completely got rid of the error.
I had python 2.7 installed and enthought canopy. I wanted to switch to python(x,y) to access a full version of the OpenCV library. python(x,y) installation complained about python 2.7 already being installed after:
1)Using windows control panel
2)Removing all lingering python files
3)Removing the windows path as suggested above
Not until I removed all registry entries related to python/enthough did python(x,y) install without issue.
I installed Enthought before. When I wanted to install Python(x,y) instead, I met the problems above.
After I had tried to uninstall Enthought and Python(x,y) from the Control Panel and then restart the PC, the problem still occured the next time I installed Python(x,y).
I solved this problem by:
deleting all the relevant files in C:/User/UserName/AppData/ about Python, including the third party softwares like Enthought;
deleting the Path in user and system Environment;
=====the two steps were failed if I didn't do the third step.=====
deleting the register keys as #Daniel said. (include all the relevant keys with the prefix py if you installed the third party software about Python. )
HKEY_LOCAL_MACHINE\Software\Python\
HKEY_CURRENT_USER\Software\Python
Locate that set up file which was used to install Python. Run it and choose repair. If that doesn't solve the problem. Go to c:\Python(x,y) and delete this folder completely by shift+Del.
Run that set up file again and click on "Change" which will ultimately install the Python again. By default in my case option to add path and making that version of Python the default on my system was unchecked which can be figured out by seeing the red cross mark in one of the installation screen. Click on it if you want set up to make it default Python version and also click on the option to indicate you want the path to be added in windows environment variable.
No need to touch registry as previous ones will be overwritten again.
In my case it worked. I was getting error like:
Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding
Besides that un-installation was failing from control panel. So above steps solved all of my problem. Hope it helps.
I Repaired/Modified to install all the components for the Python
version I wanted to uninstall.
Once that was done, I clicked on Uninstall/Change and that uninstalled it for good.

Categories