Visual Studio Code, pylint complaining about "Unable to import XXX" - python-3.x

I am using Visual Studio Code to work on a large python project with many modules.
My settings.json looks like this:
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.autoComplete.extraPaths": [
"C:/Users/.../repos/platform",
],
"python.linting.pylintPath": "pylint"
}
After that inside the code. I am getting a ton of error on all import modules which are inside the platform-folder.
I have python3 installed with python extensions and pylint installed as well.
I have searched for over an another and tried many different suggestions but none has worked for me so far.

The Current Problem you are facing is not regarding code formatting (by pylint).
you would rather want to choose the interpreter you want to have Intellisense for.
they are provided in docs as followed. link.
Hope this helps.
If it's TL;DR for you.
just press F1 on vscode window and type Python:Select you will get right prompts.

The answer above helped me out, thanks #srinath samala! Sharing why this worked for me in case it helps someone else.
I've been running Python on Windows 10 for a while, and months later installed Anaconda, which I don't think I did quite according to best practices. Windows machines can be annoying about proper PATH config etc...I probably need to uninstall and reinstall anaconda?
In any case, using the F1 key and Python:Select to point VS code toward which Python.exe file was being used made the difference here. Apparently using pip install in a windows bash session might make those packages available for one environment v the other? I'm sure this has something to do with my own (currently janky) directory structure, but VS code defaulted to Python's original home, and I got the import error. By selecting anaconda's version it found the package. Hope this helps someone else!

Related

I have vs-code installed on a Mac and since a few hours it won't underline errors in Rust

Yeah due to Christmas I went over to my mother but still wanted to improve my skills in rust. For one day everything just worked fine, but now vscode doesn't underline the errors.
https://imgur.com/a/LxAe8f6
here a pic how it looks, I have rust-analyzer installed. It should underline something because the method doesn't return. anything.
Do you have any idea how to get rid of the Issue I already reinstalled twice.
Are you in main.rs?
If you are in a module file or lib.rs you need to import the files with use.
Other than that, I don't know, you could try enabling
"rust-analyzer.trace.extension": true,
In your settings.json file and checking your log output.
I had some issues after installing the latest version so you may want to head to the rust-analyzer extension page, click the drop-down arrow next to Uninstall and selecting Install older version, I just used a version that was 11 days old and it seemed to fix things.
EDIT: There is an issue showing VSCode downloads the wrong/old version.

Python 3.10 - ModuleNotFoundError: No module named 'win32.win32ui'

I just updated my python from 3.7 to 3.10 and now there are import error's.
While I just needed for import win32gui turn into import win32.win32gui as suggested here. There seems no other syntax for import win32ui, after some research I found this github report that has been closed with:
That's very helpful, thanks, and I can reproduce this in visual studio
I didn't consider that an exception was being caught and ignored. Turns out we aren't holding the GIL when we call back into Python -
I've no idea why this is different in 3.9 vs other versions, but the
fix is simple and is safe in all versions.
While there is suggested to comment out a line in a file named win32control which I apperantly dont have or find. Neither it seems possible in my compiled files that looks like:
G Áàȉ x#;÷щ
Nor do I understand the wheel solution and what to do with it, since I am still a beginner with hobby experience in python programming.
Update I just found this Q&A but not sure if it is related.
While it helped me on my other device to just reinstall my older python version, as stated in the comment section:
#CristiFati thanks for your reply. Since I installed my earlier
version of 3.7.2 again pywin works fine even if I run the code with
IDLE Shell 3.10.
This wasnt possible on my new device, but the Running as a Windows Service helped me out this time.
Manually copy pythonservice.exe from the site-packages/win32 directory
to the same place as these DLLs.

OpenCV 3.x Documentation in PyCharm

I've compile OCV 3.4 on my Mac. Everything runs fine, PyCharm works, QT5 bindings are fine.
I have one problem: Don't know how to add the documentation for OCV in PyCharm.
I know it's under ExternalDocumentation but how do I specify the right path???
I have the generate doc files on my HD (OpenCV/doc/html and OpenCV/doc/javadoc)
I have installed opencv-python via pip install opencv-python (see https://pypi.org/project/opencv-python/ for more details) and now I can see all the docs with Ctrl+Q shortcut. The only problem, I was not able to get a nice formatting:
Help on openCV function in the Documentation tool window
Still it simplifies things a lot comparing with the manual installation I had before.

Configuring interpreter in PyCharm: "please use a different SDK name"

I have been using Pycharm for years and have never had any problem. However, after my most recent PyCharm update I can no longer configure the interpreter.
Also each time I create a new project it creates a vent directory under my project. When I go to File/Default Settings/Project Interpreter, I am provided with new options.
In this window it allows you to configure a virtual environment, the conda environment, and the system interpreter. I am assuming that I should configure the system interpreter. From there I point PyCharm to the interpreter on my Mac at /usr/local/Cellar/python3/3.6.3/bin/python3 and hit OK.
It then takes me back to the main window where it shows the path in the project interpreter. At this point I hit apply and get a message:
Cannot Save Settings please use a different SDK name
It doesn't matter which interpreter I choose, I get the same message. Has anyone else come up with the same problem and how do I fix this?
Interestingly my old projects still work correctly.
I had the same problem while setting up the virtual environment for my project and no matter if I create a new virtual environment or select an existing one, I get the warning:
"Cannot Save Settings please use a different SDK name"
Finally I found the solution:
Click on the project interpreter dropdown and select show all.... There you might be having multiple virtual environments with same name. Now here is the conflict you need to fix manually by renaming them so every item has the unique name.
I ran into this issue when trying to get docker up and running with Pycharm 2018.1 and using the container's Interpreter. I would get the error below.
"Cannot Save Settings please use a different SDK name"
The issue I had was due to having multiple python interpreters of the same name.
Under Pycharm || Preferences || Project Interpreter
Click "show all" within the Project Interpreter dropdown and then delete any / all interpreters that you don't need.
How fix this in Windows 10:
close Pycharm .
delete this file: C:\Users\<username>\.PyCharmCE2018.3\config\options\jdk.table.xml
open Pycahrm again and load all python interceptors again.
Jon; I too noticed the difference in the latest version of PyCharm. It seems that it now has an affinity for the latest tool 'venv'. When you create an interpreter - that is what you get.
You can still create a virtualenv manually and point it there instead. I haven't looked into pointing it to a base python-bin because (frankly) you shouldn't generally do it.
My advice (and my proposed answer) is to embrace the change and let it create a 'venv' for you. From there, do all of your installs by "alt-F12". That will open a console with your virtual environment activate -- so your PIP installs into the virtual environment.
Once I began using virtual environments, I never looked back. It has made life much easier in the python world. Pycharm seems to know this as well and is trying to really encourage you to do the right thing.
SteveJ
[Edit Alternate way to get to terminal]
This may be a known issue of PyCharm and using the method of the accepted answer may not resolve it. Please see https://youtrack.jetbrains.com/issue/PY-27251.
You can close Pycharm and remove jdk.table.xml file from ~/Library/Preferences/.PyCharm2018.1/options directory (Mac version), then start PyCharm again.
Warning: By doing this, all your existing setup of python interpreters will be erased and you need to re-setup them again.
I had same error:
I deleted all invalid project interpreters ( they are red)
then I did https://stackoverflow.com/a/60583928/3842788
You cannot have 2 or more virtual environments with same name. Even if you have projects with same name stored at 2 different places, please give unique name to its venv. This will solve your problem.
To check all the virtual environments:
Go to File >> Settings >> Project: your_project_name >> Project Interpreter
And rename the venv name.
Go to Project > Project Interpreter > Select the dropdown menu > "Show All".
For me, there were several Python environments, two of which were red with an tag. Remove the envs that are red / have an tag, select the remaining valid one, and re-apply settings.
In my case, I moved my project to a different location and PyCharm started complaining about Cannot Save Settings please use a different SDK name. At the top of the main editor, it asks me to Configure Project Interpreter. I clicked it, and then ...
My solution
Remove all existing interpreters that are marked as invalid in the preference.
Select the interpreter in the moved venv subfolder in my project.
Without doing both, I kept getting the same "SDK name" error. It seemed that the project thinks that it already has an interpreter called "python.exe", if you don't actively remove all "invalid" ones.
I solved this issue by cleaning the Pycharm memory cache

Can't access PyQt functions in PyCharm

I've recently installed Pycharm and PyQt to start application development, but I can't seem to access the PyQt functions in my projects. The same code works if I open an example of PyQt, but if I paste it in my project, I get these squiggly underlines and an error upon compile.
The issue is with the pycharm skeleton file generator, encounters issues with some pyqt files, there is no pattern as to why this happens. I have had similar issue with pyqt 5.3 and the pycharm 3.4.1. I and several others spent hours on the issue, browsing the web for clues and trying everything suggested to no avail.
We eventually found a post on StackOverflow that indicated a solution. In our case applying it was quite simple: we did not observe this problem with pyqt 5.2 therefore we copied the skeleton files from that version into the 5.3 skeletons folder. The details of how to do this are available in a comment that I posted on the pycharm bug tracking site: PyCharm auto completion doesn't work for PyQt 5.3. The issue is discussed in other ticket I just found, which might provide an actual fix instead of just a temporary patch: Unresolved reference in PyQt for QtGui module.
Late , but after none of above methods not work I closed pycharm and restarted pyCharm by restarter.exe in this path:C:\Users\<user-name>\.PyCharm2016.2\system\restart , then reopened pycharm. In my case it just worked :)

Resources