VS Code Opens Folder of Modules - python

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.

Related

VSCode loads the wrong python version in the interactive window

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.

VS Code: "NO FOLDER OPENED"

This may seem trivial, and I admit that it is more a question relating to ease of access in VS Code.
My VS Code window shows "NO FOLDER OPENED". How do I fix this?
Up until the other day when I set VS Code as my default app for .py files (this is the problem), I could see any and all folders, sub-folders, and .py/.ipynb files on my Explorer tab. I am both new to Python and VS Code. I have tried these things to fix my problem:
Attempted to reset to all of microsoft's default app associations--the aforementioned files still open with VS Code.
Attempted to change each file's "Open with:" path (by accessing its properties)--it gives no other option, since PowerShell and CMD are not "apps".
Found this that got close but did not target my specific problem.
Found another article which refers to Windows 7--I didn't read it after seeing this.
I have done various other things, but I think you get the point; I'm at a loss!
This problem seems annoyingly easy to fix. I would rather see if there is some type of setting, in VS Code or Windows, that I am overlooking before searching for a complex work-around.
I'm also new to Stack overflow. I hope this is a "valid" question.
It's important to keep things organized even when you are new to coding. In VScode it is pretty simple to do that. I suggest you to make a folder for your projects and also for other purposes like practicing on examples.
Lets say you created a folder on desktop named Python, and you keep all your .py files in there, then you don't have to open each of the python files by double clicking it, it's a wrong practice. Instead, open VScode application from the start menu or desktop, then go to file > open folder > Python(the python folder you can create on your desktop). This way it opens a workspace(Folder) where you can work with different Python files or any other files.
With Ctrl key pressed, press O and then K. Then, select the folder where your python file is located.

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.

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.

.py files not opening in IDLE from OSX Finder?

I recently re-installed Python 2.7.3 from python.org on OSX 10.8.2, and now nothing (literally nothing I can see) happens when I double-click on .py files in Finder, or when I right-click/Open-With/IDLE(2.7.3). (Edit: IDLE is already set as the default program to open .py files; the "right-click" part was just to illustrate I couldn't open them either way.)
I have Tcl/Tk 8.5.13 installed (re-installed after I re-installed Python), and I can open IDLE itself just fine, so this isn't that issue where IDLE won't work without the right version of Tcl/Tk. I can also open .py files from the Terminal using idle -e file.py without a problem.
I did notice that the Python Launcher activates when I open files this way, and is absent when I double-click on .py files in Finder (although again, literally nothing happens when I do this--I have the IDLE icon in my dock and it doesn't start bouncing or anything). Could this be a Python Launcher problem? If not, does anyone know what's going on here?
Update: I tried opening IDLE first and then double-clicking on .py files, and that works. So it seems it's just an issue of IDLE not being opened when you try to open a .py file in the Finder.
I know that means I now have at least three other ways of opening my .py files in IDLE, but I really like just being able to navigate to a file in Finder and open it when IDLE itself is not yet open. So I'd still really like to solve this problem if possible (also I really hate when stuff that's just supposed to work doesn't).
Update: Per Ned Deily's suggestion I checked for errors using Console.app and found:
3/8/13 10:42:38.006 AM com.apple.launchd.peruser.501[276]: ([0x0-0x199199].org.python.IDLE[1975]) Exited with code: 1
pops up whenever I try to double-click a .py file in Finder.
Make sure you have set the intended instance of IDLE as the default application for all .py files. One way to do so is to select a .py file in a Finder window, then select the Finder -> File -> Get Info menu item (or Cmd-I). In the Open with: section, pull down the application menu item and select the desired IDLE; if you have multiple copies of IDLE installed, select the Other.. menu item at the bottom of the list and use the file chooser to select the right version of IDLE. Then, click the Change all... button to Use this application to open all documents like this one. You should now be able to launch a .py file in the desired IDLE by double-clicking. If this doesn't work, examine system.log to see if there are any error messages being logged. You can use the Console utility to examine logs (/Applications/Utilities/Console.app).

Categories