I am developing in Python using Visual Studio Code. I put breakpoints in the code of an external package in my virtual environment. But the breakpoints are never getting hit. Even by setting the variable justMyCode = false in the VSC settings.
Could there be another reason ?
I encountered the same problem.
The reason is that "The venv folder is not used to store external packages. They must be activated to access the modules installed in them, but the code that uses these libraries should remain external."
The solution is to move the external files with breakpoints out of the virtual environment (like "venv") folder.
Related
Always when I create a new Python project file, in Visual Studio Code, and I import some modules, it marks the ones VSC can't find, but they are already installed in virtual environments.
How can I fix this bug? Thanks!
Select and activate an environment
By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. If it doesn't find an interpreter, it issues a warning. On macOS, the extension also issues a warning if you're using the OS-installed Python interpreter, because you typically want to use an interpreter you install directly. In either case, you can disable these warnings by setting python.disableInstallationCheck to true in your user settings.
Check this link: https://code.visualstudio.com/docs/python/environments
I have a shared flask web project I am working on with 2 other developers, one of the developers initialized the venv on his pc, uploaded his project structure to github from where I cloned his repo.
Now I when I start vscode and open the project folder, python does not auto detect the venv and asks if it should set is as the interpreter, the only option I have is the default system wide python install, and not the venv python interpreter.
I tried adding it to the list by using the command python:select interpreter and then finding the python.exe inside the venv/scripts folder, but this does not work and vscode still asks for a interpreter.
I also tried manually adding it inside of my workspace settings.json file like so
"python.pythonPath": "C:\\laragon\\www\\Proftaak\\venv\\Scripts\\python.exe"/
But vscode also gives an error on this saying the interpreter is not valid.
How would I fix this?
This is not expected to work as virtual environments are not designed or meant to be movable. They are meant to be created on each machine you need a virtual environment on. As such, I suspect that the virtual environment does not work outside of VS Code which could prevent it from selecting it as a possible working environment.
I face a strange python virtual environment synchronous problem which might be not solved yet, and I have tried to find lots of related issues and technical words on the web.
Here is the situation
A and B are two laptops of me, and I built python virtual environments by using the command of virtualenvwrapper: "mkvirtualenv temp_1" on A at first. The absolute address of temp_1 on A is D:\Dropbox\python\envs\temp_1, then it was automatically synchronized by Dropbox after being built.
Due to the synchronous setting of my Dropbox, it of course was synchronized and downloaded to B when I using B.
However, the Visual Studio Code installed on B can not find the python interpreter in the python virtual environment temp_1 and always show the message
no python interpreter is selected
while it can definitely be detected by the VS Code installed on A. Besides, the VS Code always only show the original python interpreter which is installed under C:\ (C:\Python\Python38-32\pyton.exe) but in the temp_1 no matter how I set the absolute address of python interpreter to python.pythonPath: in settings.json of User setting and Workspace setting in VS Code on B.
If I chose the "original python interpreter" in VS Code on B, the problem that IDE can not find or recognize python interpreter could be solved owning to the VS Code on B will rewrite the interpreter address to python.pythonPath:. But, relatively, the same problem will shows on A after the rewritten files of temp_1 being synchronized by Dropbox to A; hence, instead, the VS Code installed on A can not find and recognize the python interpreter in temp_1 and shows the issue message and provides the original python interpreter under C:\ of A when I return to use VS Code installed on A to code the python program files.
Below is the solution I use temporarily
Every time when I change using the laptop, I have to use the command of virtualenvs to create a virtual environment that is Exactly identical to temp_1 in the virtual environment by itself. For example:
D:\Dropbox\python\envs> workon temp_1
(temp_1) D:\Dropbox\python\envs> virtualenv temp_1
After doing the steps above, the VS Code on A (or the laptop where files of the virtual environment are overwritten by Dropbox synchronization) can find or recognize the interpreter which was built in temp_1 but the original python directory under C:\
Even it works, it is very annoying to me (or anyone). Is any solution can synchronize the python virtual environments and let them be found or recognized by VS Code install on different laptops with Dropbox?
It looks like you placed your code inside the virtual environment which isn't the proper place to put it. I would create a directory for your project, put your code in there, and then install the virtual environment into a subdirectory (e.g. .venv). Then you can set .vscode/settings.json to have a "python.pythonPath: ".venv/Scripts/python" value.
I am having some trouble with my Eclipse debugger. Every time I set a breakpoint on Python source files, when the breakpoint is hit Eclipse opens up the associated pyc compiled file.
Below are a few things I have tried:
Creating a new Eclipse project with the code
Deleting all settings files within the code
Switch to a new workspace
Re-install eclipse and PyDev completely.
The problem persists. I don't know what could possibly be causing this. The issue only occurs when a breakpoint is set. However, that renders breakpoints useless in Eclipse.
This issue only began after I tried to set up Visual Studio for Python development. In Visual Studio this issue does not occur.
Can you check if you have pydevd installed somewhere in your system and remove it if that's the case? (i.e.: run without debugging import pydevd and if you find it remove it from your interpreter).
The PyDev debugger is used in other products (such as PyCharm and Visual Studio), so, my guess is that a non-compatible version is installed somewhere instead of using the version which is shipped along with Eclipse/PyDev.
When I create a new remote Python interpreter, IntelliJ doesn't find any dependencies to my code and doesn't seem to index any libraries. Most of the code is red. I think I've pinpointed that to the "classpath" being completely empty, which is unlike some other Python SDKs that I have added (local ones). Some of the times I am able to get it to populate the classpath with paths pointing to the IntelliJ Caches directory by clicking around in the interface, but I most of the times it does not work and I cannot reproduce how to make it work. How do I make sure the classpath gets populated correctly?
I am using IntelliJ Ultimate version 2016.2.1. with the Python plugin version 2016.2.162.43. I am developing on a Vagrant virtual machine and I'm adding a Python remote interpreter that is inside a virtual environment (venv) inside the virtual machine. When I add the remote interpreter, I use:
On the SDKs tab - the + button.
Python SDK
Add Remote
I select the Vagrant option
Point it to my Vagrant project directory.
Point it to the python3.5 executable inside my virtualenv
Add the SDK
Then the classpath looks like this: https://www.dropbox.com/s/3xbzopb4y9bhn0u/Screenshot%202016-08-11%2017.19.43.png?dl=0 and IntelliJ doesn't recognize any libraries/builtins. For other SDKs, the classpath contains several entries with remote_sources, python_stubs or python-skeletons in the name and they work.
As a workaround, I copied every entry from the local python interpreter classpath to the remote one and everything seems to work
Edit:
Actually, I don't know what triggered it, but some days after I wrote this, I noticed that IDEA started downloading source files from the server. I went to the interpreter settings, and the classpath entries I had manually added were gone and replaced by "system/remote_resources" entries. I think this is how it's supposed to work, but unfortunately I don't why I didn't work from the start nor how to trigger the correct behavior, it just started working on its own.
While this issue is a bit older, I had the same issue today with IntelliJ IDEA 2021.2.
I was able to solve this by using Navigate -> Search Everywhere -> Type interpreter -> Select Rescan Available Python Modules and Packages.
This prompted downloading of the remote resources and indexing. Afterwards, the classpaths were filled in properly.