I followed Microsoft excellent tutorial to create a Python extension in c++. Everything works fine, I can compile, run and debug the code (both the Python and the C++) in Visual Studio 2022.
However, the issue is that I want do this within a venv, this was possible with Python 3.7.0 but now when I create a venv with Python3.10-64 I can't debug the C++ part.
I have included the include and libs of the "global Python" in the Visual Studio 2022. Do I miss something when I create the venv with c:\python310-64\python -m venv venv? There seems to be a lot less in the Script folder now with Python3.10 compared to with Python3.7.
is there anything that I can change within Visual Studio 2022 to hit the C++ breakpoints when I run Python from venv created with Python3.10?
When I look at what modules that are loaded when I start the debugging from my venv, and right click to find the symbols for Python.exe it looks like this:
.
Compared to this long list when I start the debugging with the "global" Python installation:
Woho! I finally figured it out. The venv needs to be created with --symlinks like this C:\Python310-64\python.exe -m venv venv --symlinks. You need to run the command as administrator to get it to work!
Related
I have just started working on my new pc and just to get a feel for it I wanted first to start working on python files, so I started first by just wanting to run WSL on windows and it installed correctly but when I want to run any python using the run python file on the top right on VS code, this is what gets executed $ C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe f:/Projects/hello.py
And this is the error: -bash: C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe: No such file or directory
I have no idea what's causing it but when I run the file using 'Shift + Enter' which is: Python: Run Selection/Line in Python Terminal it seems to run the single line correctly but it gives me this error instead:
print("Hello, world")
-bash: syntax error near unexpected token `"Hello, world"'
but when I run it using python3 hello.py, it works perfectly fine?! I'm so lost as to why this is happening and how could I fix it.
Might be relevant: I'm using windows 10, installed python 3.10.2 from windows store, all of that is in VS code and the python code is one line: print("Hello, world") and I changed the permissions of Local/Microsoft/WindowsApps so it's now accessible by all users to view/read/edit/run, made sure that python3.10.exe exists(on the WindowsApps and it works perfectly) and reinstalled it many times, tired python3.9, and tried to install python from the website instead of the windows store and still the same, manually added python to PATH and tried .venv and didn't work. when I launch python3.10.exe outside vs code it seems to run perfectly, I have worked with python before and it used to work fine now I don't know what's wrong.
I have seen other questions of the same problem I'm having here but none of them solve the problem.
No such file or directory C:/Users/...
For wsl, the Windows filesystem is accessible, but it has a different path. It is mounted under the /mnt folder. So you would find your python .exe under /mnt/c/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe. This said, the executable file is meant to work on Windows, and it doesn't really makes sense to use it on Linux when you could run python within your wsl distro.
python3 works perfectly fine
This is because most Linux distributions come with python3 pre-installed, so you can use it already. To see where it is located, you can run the command which python3, or python3 --version to check its version.
If you want to change version, you may consider download it from you package manager, apt.
I also suggest to install python3-pip if you don't have it already to get the pip package manager for python.
In my case when I ran into this.. I discovered pyenv. This allows you to download more than one version of python. You can then go into a specific directory, such as your python project and issue a python local 3.10.0 (for example). Here's a link on how to install it as well as poetry which is a virtual environment manager that is become very popular. You can also create an alias for python that works off of this. I add this command to my alias file and source it from my .bashrc. alias python='pyenv exec python3'
Just gone through the process of setting up python and all the installs using cmd and now i want to use
brownie bake
To clone some code and it gives errors as it cant locate brownie... I've set environmental variables for the path (that's how I got it to work in cmd)... I've installed the python extension and chose the python.exe file in my new install in the compiler by clicking the bottom left... How can I make visual studios Code use only the python and all library's I installed?
if i run
python
in the terminal it opens up windows store for python install but i can run my version by using
py
First, Disable the python command to open the windows store:
Search Manage app execution aliases and unselect App Installer of Python:
Second, You need to check which python you have installed your packages to:
And make sure in the VSCode you have selected the right interpreter(In the following picture, they are different).
I am trying to learn more about Python in my spare time. I am a .net developer. I have downloaded a simple private open source project. The developer of the repository advised me to clone the repository and then run the project:
source .env/bin/activate
python3.6 ./project/main.py -c config.json
It works as expected. I am now thinking about debugging so that I can step through the code and debug it. Therefore I have downloaded Visual Studio Code and then installed the Python extension. I then start debugging and everything still works as expected. I opened the Visual Studio Code terminal and I see that Visual Studio Code runs the following:
bert#bertvb:~/myapp$ source /home/bert/myapp/.env/bin/activate
(.env) bert#bertvb:~/myapp$ /usr/bin/env /home/bert/myapp/.env/bin/python /home/bert/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/lib/python/debugpy/launcher 43369 -- /home/bert/myapp/myapp/main.py -c config.json
How does Visual studio Code know to run the first line i.e. to enter the virtual environment? I was advised that this would have to be run manually
Visual Studio Code automatically scans your workspace folder for any virtual environments. If it finds one, it will automatically enable it and select the Python interpreter installed in this virtual environment. If you want, you can disable this behaviour by setting the python.terminal.activateEnvironment option to false.
For more information, see the "Using Python environments in VS Code" documentation page, specifically the section "Where the extension looks for environments".
Image case for the problem
I was following the Visual Studio Code tutorial for python here
https://code.visualstudio.com/docs/python/python-tutorial
I downloaded Python, installed the python extension in Visual Studio Code and set the python interpreter to python3.8 . I also checked the workspace settings to see if it had given the correct path. Then, I wrote a simple hello world program but this is the error it is giving me.
This is the python path it has in the settings.
C:\Users\Dell\AppData\Local\Microsoft\WindowsApps\python.exe
Program:
print("Hello World")
Error:
C:/Users/Dell/AppData/Local/Microsoft/WindowsApps/python.exe c:/Users/Dell/hello/hello.py
-bash: C:/Users/Dell/AppData/Local/Microsoft/WindowsApps/python.exe: No such file or directory
I tried uninstalling and installing all the extensions again but it didn't work. I also uninstalled and installed all python related things on my computer. That didn't work either. What should I do?
reinstall python and this time, add python to the PATH (there is an option on the installation screen. Check it as it isn't checked by default). Then try running vs
Your environment path is not configured properly reinstalling python will fix this make sure you install python from actual application and not from vscode.other solution is that you can set the enviornment path manually just go to the environment variables> under user variable set the path to your python.exe the above mentioned location seems unlikely it should contain main python folder such as Python37/....
I will suggest you follow the link mentioned in this blog post to have python installed and working with Visual Studio Code. https://techdirectarchive.com/2023/01/17/getting-started-with-python-automation-in-windows-with-visual-studio-code/
Microsoft recommends installing python from the Microsoft Store. since installing from the Microsoft Store uses the basic Python3 interpreter, and handles the set-up of your PATH settings for the current user (avoiding the need for admin access), in addition to providing automatic updates.
I have a virtual environment set up inside bash for Windows (Ubuntu) and VS Code installed (Windows). The Python project runs well inside the venv in bash but I would like to now debug it through Visual Code.
I'm trying to set the python.pythonPath as follows inside settings.json
{
"python.pythonPath": "C:\\repos\\myrepo\\venv\\bin\\python"
}
The error returned is "Please validate the path ..."
Note that through bash for Windows, the filesystem is accessible through /mnt/c/
As for the auto-detection of Python, it only lists the python.exe installed on the windows filesystem (which is of no use to me).
https://code.visualstudio.com/docs/python/environments explains that doing this should be sufficient but doesn't seem to work.
It doesn't work because WSL isn't officially supported yet by the extension as of version 0.8.0. See https://github.com/Microsoft/vscode-python/issues/67 to up-vote and track the issue for detecting WSL-based virtual environments.