Visual Studio Code, ReStructurdText extension can't find Python - python

I'm trying to use the LeXtudio ReDtructuredText extension for Visual Studio Code. It's not working, and the reason is not clear.
After I installed the extension I tried to use it by clicking the "split screen" icon below the menu bar, and I got a popup message that said, "Please review Python installation on this machine before using this extension."
I clicked the "Learn more" link and learned that the extension depends on Python 3.5 or later. My system runs Python 2.7 because our production environment uses tools that depend on it, but I have Python 3.8 installed too. I followed a "learn more" suggestion and added python.pythonPath to the VS Code settings file. Then I tried again, and got the same message.
Did I modify the settings file right? I think so; here's how it looks so others can check. (Line 2 has been added.)
{
"python.pythonPath": "C:\\Program Files\\Python38\\",
"editor.minimap.enabled": false,
"breadcrumbs.enabled": true
}
Did I put the right value in the string? I think so; when I examine C:\Program Files\Python38\ in File Explorer I see that it's a Python installation's top level directory, and python.exe is in it.
Did I modify the right file? I did; when I changed "breadcrumbs.enabled" from true to false, the editor's breadcrumb display disappeared instantly -- I didn't even have to restart the editor.
Any ideas?
The extension instructions also recommend using Microsoft's Python extension to change the setting. It says that this "really makes configuring Python environment easier," although it doesn't explain how.
It says, "Once you have that Python extension installed, open conf.py in VSCode." It's not clear what this is for, since the settings file is named settings.json, but I hoped that when I opened the file that would become clear. But the instructions don't say where this file is, and I can't find it. I searched my user directory and both Program Files directories, and the only files I found with the name conf.py were in Sphinx projects... not a likely place to put VS Code settings.
Any ideas?

Related

Visual Studio Code Pylance (report Missing Imports )

I keep getting error "X" could not be resolved Pylance(reportMissingImports) [ln 1, Col8]
I AM in fact a beginner, the basic youtube "fixes" are NOT working
View Command Pallet ... NOT working
Terminal pip install .... NOT working
I am running the Zip install on my work computer and im guessing it has something to do with a directory. but i cant seem to figure it out. the bottom left corner shows the python version which is ( Pyhton 3.110a7 64-bit(windows store)
Pylance requires you to set the Python PATH:
If you're in Mac/linux, make use of :
which python3
And in windows:
where python
So that the path in which you're python is installed is returned
Copy that path.
Go to your vscode and open the settings.json file (CTRL + SHIFT + P, and type "settings.json" at search bar)
Add the following key to the json file
"python.defaultInterpreterPath": "/Users/YOURUSERNAME/opt/anaconda3/bin/python3"
This was just an example, the PATH could be something more like
"C:/users/YOURUSERNAME/anaconda3/bin/python3" in case you're using windows.
The following documentation from python for vscode provides more information about how to configure Python for Visual Studio Code:
https://code.visualstudio.com/docs/python/settings-reference
There’s a very comprehensive discussion on settings in VS Code here: https://stackoverflow.com/a/63211678/5709144.
In summary and with regard to this specific case, it’s better to change settings by going to (on a Mac) Code > Preferences > Settings.
Enter python.defaultInterpreterPath in the search box at the top of screen. The current path is shown in an editable text box.
Enter any path you like here - foobar, mother, whatever you like. It doesn’t matter as, if the path isn’t recognised by VS Code, VS Code lists those that are. The only reason you enter the path is to get the list of potential paths. Click on one of these accepted paths and you’re all set up.
As asked, your question doesn't specify whether or not your imported module is correctly installed. If it isn't, then this answer will not apply. However, if your code works as expected and you're getting a false warning, then you can ignore the warning by doing the following.
Create the file .vscode/settings.json in your current directory and then add the following:
"python.analysis.diagnosticsSeverityOverrides": {
"reportMissingImports": "none",
}
Be warned however that this will ignore all missing import warnings, not just the one you're trying to get rid of. Therefore, if you have any imports that are legitimately missing, the warning will not be there.
Also, on some occasions, you might have configured your environment by adding custom paths that Pylance can not detect.
In that case, you can use the python.analysis.extraPaths parameter to add more paths to your project, such as :
"python.analysis.extraPaths": ["app", "another/path/etc"]
(Source: https://dev.to/climentea/how-to-solve-pylance-missing-imports-in-vscode-359b)
If you are using the VS, Please go to the settings .. search for Advance path and then ADD it (/.source) it should solve the problem.
Hope you have installed the Pylance in your system correctly.

visual studio code pylance search folders

I have a project with some python in it - the python is part of a larger thing - there are several programs in several directories inside a root git - and there is some common code in yet another directory.
Running works fine - but pylance in visual studio code sees all of the dependencies as errors, even though most are in the current directory of the script I'm editing. If I open that subdirectory they work fine - but I really want to have visual code open at the larger project level.
Is there any way to bung a file somewhere in the directory that tells pylance "here is the python search path" or something?
You may search for settings about additional import search resolution paths:
"python.analysis.extraPaths": [
"path1",
"path2",
],
Please have a try.
More information view Pylance Settings and Customization.

problem on setting up python on visual studio code

After installing Python and Visual Studio code as followed on this link:
https://www.youtube.com/watch?v=dNFgRUD2w68&lc=UgxjG9Bd_Uwm9duwpld4AaABAg
I can't see the reload button in the VS but there are two button; one is disable, and the other is uninstall. Do you know why I don't have reload button and how to resolve this issue?
You don't have to reload the page. Python is already installed.
Just close the current window near the "Extension: Python".
If for some reason VSCode still can't recognize python files, just close it and open it again.
After finishing your Python file in VS Code, save all changes, head to the terminal and enter the directory of the python file(A directory is where you've saved your file), and type python example_file.py.
Of course, you can change the name example_file.py to your actual file name.

Visual Studio Code (Mac OS) rename symbol doesn't work

When I right click and try to rename a variable name in Microsoft Visual Studio Code on Mac OS Mojave, it prompts for the new name, I hit enter and nothing happens.
I have Python extension and Latex extension installed.
Usually there are no errors, no nothing.
Sometimes, there's a little box that pops up saying "No Result. No Result".
The python interpreter I selected was a Conda install.
I ensured rope, and pylint were installed.
Expected behaviour:
right click > rename symbol > type new name > enter > all instances of variable renamed.
Observed behaviour
right click > rename symbol > type new name > enter > variable has same name everywhere, including spot of renaming.
It turns out the solution was simple, but frustrating. To do refactoring in VS Code (at least for python) you need to be in a workspace.
I solved the problem by first closing the open folder I was in:
File > Close Folder.
then navigating to a sub folder of .py file I was editing, and opening it. In my case it was
Click the little document icon in the upper left of screen
In the welcome screen, choose "open folder"
navigate to my desktop folder (where my .py file is)
Now refactoring works as expected
Click on file icon in upper left of screen > in the welcome screen
I use Pylance with a workspace and had the same issue. For me the solution was to restart the language server (from the Command Palette). I find it faster than closing and opening the folder.
Ctrl+Shift+P > Python: Restart Language Server
Choosing a folder did not solve the issue for me. I switched to a new language server called Pylance and everything works fine now.
I just found out that if you use Pylance (Pyright) and have a pyrightconfig.json or a [tool.pyright] section in pyproject.toml, this can cause refactoring to fail.
In my case I had not put the localtion of the script into the include array in pyproject.toml so it was giving the "No results" error.
In my case the solution was to reset the Python Language Server setting:
"python.languageServer": "Default",

PyCharm cannot find library

I am using PyCharm 5 to run a Python 2.7 (Anaconda) script in Ubuntu. My script imports a module with import tensorflow, but this causes the error ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory. So, it seems that the library libcudart.so.7.0 is needed by this module, but it cannot be found.
Now, I have seen that this library is on my machine in /usr/local/cuda-7.0/targets/x86_64-linux/lib. So, in PyCharm, I went to Settings->Project Interpreters->Interpreter Paths. This had a list of paths, such as /home/karnivaurus/Libraries/Anaconda/python2.7. I then added to this list, the path mentioned above which contains the required library.
However, this did not fix the problem. I still get an error telling me that libcudart.so.7.0 cannot be found. If I run my script from the shell though (python myfile.py), then it runs fine.
How can I tell PyCharm where to find this library?
I have noticed that if I have print sys.path in my script, the paths it prints out are entirely different to those in Settings->Project Interpreters->Interpreter Paths... should they be the same?
I came across this problem just recently using a remote debugger, however I believe it's still the same solution. I just added the following to the Environment Variables section in the Run/Debug Configuration options found in Run > Edit Configurations... dialog: LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
The path to your cuda library seems strange to me. I would expect it to be /usr/local/cuda-7.0/lib64 or /usr/local/cuda-7.0/lib.
Did you follow all of the cuda installation procedure?
If you type env on the command line, do you see a path to cuda in your LD_LIBRARY_PATH?
Update from comments below:
The issue is that PyCharm was invoked from the desktop, and wasn't getting the right environment variables. Solution is to either:
invoke from the command line,
create a script to set environment and then invoke, and make a link to that script on the desktop,
or set environment variables on the desktop item
While some of these answers are correct, and could work, I haven't seen what the OP specifically asked for, and that is where to set environments for the python console. This can be accomplished inside pycharm at:
File > Settings > Build,Execution,Deployment > Console > Python Console
In the options there, you'll find a place to define Environment Variables. Set LD_LIBRARY_PATH there.
Edit your pycharm.desktop, specify the environment variable in exec, like below:
[Desktop Entry]
Version=1.0
Type=Application
Name=Pycharm
Exec=env LD_LIBRARY_PATH=:/usr/local/cuda/lib64:/usr/local/cuda/lib64 /home/cwh/software/pycharm-2016.1.4/bin/pycharm.sh
Icon=/home/cwh/software/pycharm-2016.1.4/bin/pycharm.png
Name[zh_CN]=Pycharm
so pycharm will find cuda
Have you selected the right python interpreter in your project's settings?
See here.
I had a similar issue and changing the interpreter solved it without having to create a new icon.
The following works for me on Community edition 2019.3
To set globally for a project:
Open File/Settings/Project/Project Interpreter
click on the cog icon next to the interpreter
choose show all
click on the little folder with tree icon bottom right
add the path to "Interpreter Paths"

Categories