VSCode loads the wrong python version in the interactive window - python

I am trying to use the Interactive window of VSCode, but it loads the wrong version of Python. I want it to load the version of the virtual environment (shown bottom left), but it defaults to something else.
I have tried this approach, but I can't simply click the version and change it because it isn't included in the drop down list. I have tried adjusting the settings.json file python.defaultInterpreterPath but that didn't work (perhaps my syntax is wrong). I have also made sure that jupyter is installed in the virtual environment.
I always run VSCode in the project folder from the command line using code . but strangely, something that has worked is running it using code (without the period). This is not a solution however, because the workspace folder is not updated, meaning that when I change the project I'm working on, VSCode opens in previous workspace.

You can try to delete all the files and folders under this location:
C:\Users\${UserName}\AppData\Roaming\Code\User\globalStorage
Others:
The python interpreter of the .ipynb file was stored in the database located at:
C:\Users\${UserName}\AppData\Roaming\Code\User\workspaceStorage
Such as:
If you open a new .ipynb file in the VSCode which name has not storaged in the database, you will need to select the interpreter.
It's different from the interactive. You can find, any time you reopen the VSCode, the last time you created interactive will be disappear.

Related

VS Code Opens Folder of Modules

I, probably, have a weird question but it really annoys me. I have created Venv and installed some modules. When I click the module file to scroll it, VS code shows the location of module file in the side explorer. I guess this feature can be turned off in preferences; but, unfortunately, I cannot find it.
Add the following code to your setting.json:
"explorer.autoReveal": false
Then vscode will not open the floder when you open or click a tab or other things.

Error running 'filename'. The system cannot find the file specified (PyCharm)

I have a PyCharm project on my Windows, where I am able to run most .py files by pressing Ctrl + Shift + F10 (or running the debugger). In one of the files however I get the error
Error running 'test':
Cannot run program "\opt\anaconda\bin\python" (in directory "..."): CreateProcess error=2, the system cannot find the file specified.`
The test.py file right now only contains print('hello')
I can do this for the other files, and using 'Execute selection in console' also works fine. Given I am on a Windows machine the "\opt\anaconda\bin\python" part looks suspicious, but I don't know how to fix it.
Any help?
Copying the content to another file (e.g. test_2.py) 'fixes' the problem, but since this is a collaborative project this isn't viable.
I think your case is cause by some project environment has changed.
I suggest your open the workspace.xml which located in .idea\, check the parameters in it.
or you can delete the directory ".idea" and re-create the project locate in the original path.
Hope it work
I had the same problem in PyCharm IDE and Windows after adding new libraries and some changes.
I recreated Run/Debug Configurations with these steps (Instead of recreating the whole of project!):
Select Edit Configurations... from top panel in PyCharm IDE
Select these files and press delete for deleting them
Recreate these files likes this images:
Click green arrow or press Ctrl + Shift + F10
This is what I had to do:
Check the .idea/workspace.xml for any old venv references (there are several tags like "SDK_HOME" which store the path to the venv) and update as necessary
Check the .idea/RunConfigurations for any run configs and update them (or delete and recreate as you like)
when I installed the pycharm I had the same issue. for this, you really need to understand the concept of the virtual environment. this error comes because you run the file in another directory in which you do not create any virtual environment.
let's say you create a virtual environment in any folder located at the desktop now you run the files in any other folder located in /user/AppData/any_folder then it will show the error that the system can't find the file specified.
So be sure you run in a file in the same folder in which you created a virtual environment.
I had the same problem after downloading a project from Github. It ended up being a configuration problem.
Creating a new project on Pycharm, pasting the code in it, and using your own configuration should solve the problem.

Jupyter Notebook error. No such file or directory C:.../HOME

I have installed Anaconda2, and today decided to update to Anaconda3. I installed Anaconda3 at the same time as I uninstalled Anaconda2.
Now, Jupyter Notebook shows this error and quits every time I try to start it.
The path in the error message is: "C:\Users\Hongyi\Documents\%HOME%"
What is causing Jupyter Notebook to quit?
Okay it looks like I found a solution.
Jupyter started running after I created the appropriate folder in the appropriate path.
In my case, it is creating a folder named %HOME% (with percent signs), in the path shown in the error message.
Now Jupyter is up and running.
Thank you guys for your thoughts and suggestions.
After readed this solution I tried another one (a comfortable one for me):
Open the location of the "Jupyter Notebook" shortcut (right click > More > File location) and right click again > Properties. In the Destination field (Sorry if the label is another ... the thing is that my Windows is in Spanish and I don't remember how it's labeled this field in English) just change the %HOME% at the end for a path to your "Work Folder" (if you have not created one then just create it). And this way It works also.

Directory issues within Pycharm (free version) & Perforce

Ok, so I'm looking to switch to PyCharm from PyScripter for OS independent development. I also wanted to mention that I'm using Perforce for version control.
So what I currently do is double click a .py for editing in Perforce, and PyScripter opens up and I edit to my hearts desire. I can click on an imported function, and it'll open up the corresponding .py file and bring me right to the function. Awesome.
So I have yet to be able to achieve that on PyCharm. I'm using the community version which should be just fine for what I want, which is just an editor with some python checking & built in console.
When I set the default .py program to use in Perforce to PyCharm, I click on the .py and PyCharm fires up. Good so far. But my problem arises when I try to "ctrl + click" a function or method. I get the "Cannot find declaration to go to." I import the associated class & file.
(Just an example, not actual code). So in Transportation.py I have "import Cars", which is a .py. I do Cars.NumberOfDoors() and I get the above error. My folder structure is:
Scripts (folder)
Population.py (General support script)
Citybudget.py (General support script)
MassTransit (folder)
Transportation.py
Cars.py
So question boils down to, is how do I properly setup the root to be the Scripts folder when I click on a file from Perforce? How do I set it up that it recognizes where it's at in the folder structure? So if I'm in the MassTransit it'll set the root as Scripts folder, and same for if I'm accessing the general support scripts like Population.py?
Go to
File --> Open
in Pycharm and select your Scripts(folder) and open it. Then the Pycharm will treat it as a project and you will be able to ctrl + click a function.

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