I have a folder opened in Visual Studio Code, and a file in that folder that I am debugging. I am trying to search for a specific function that has been imported from different project. Apologies for the lack of proper terms, for better explanation, see below
- folder-with-my-projects
- project1
-file-I-am-debugging.py (function X is imported)
- project2
-file-containing-function-X.py
I want to be able to search for function X, when I have the project 1 opened in the IDE. These are all python projects, if that matters. Right now, the search only looks through files in project1 folder and completely ignores anything else. For example, Pycharm's Find in Files does exactly what I need. Is there a way to have this functionality in Visual Studio Code?
Open VScode in a directory that is a parent to both directories and search from there.
Alternatively, you should be able to use multi-use workspaces to add a folder outside your current directory into your project space which should allow you to search it. https://code.visualstudio.com/docs/editor/multi-root-workspaces
Related
So I recently downloaded a package and it is stored at /opt/homebrew/Cellar/package, yet nothing comes up when I search this in my finder. On the other hand, all of my other anaconda packages are stored in /Users/Me/opt/anaconda3 and I can see them. Why can't I find this folder?
Though the link in the “Edit:” in the question I’m about to link no longer contains the quoted text, we at least have the quote (and could probably check via archive.org if we really cared), from macos - How to view Root directory and subdirectories in Finder? - Ask Different:
The Finder and the Terminal show different contents for the root directory. Some items in the root directory are not visible in the Finder. This reduces visual clutter and enhances simplicity. If you are familiar with a UNIX-style command line you can use Terminal to view all items in a directory.
You can access it in Finder by using the Go to Folder keyboard shortcut: ⌘+Shift+G
I have a Tkinter app that uses images included in the same folder as the .py file. pyinstaller script.py produces an executable that runs but does not open any windows. This is because it is looking for images that don't exist in the same subdirectory. When I copy the important images to the dist folder Pyinstaller creates, the application runs correctly.
However, I would like to have a single executable that I can share with other users that doesn't also require them to have the images stored. The images should be bundled with the software somehow, like how commercial software (usually) doesn't require you to download assets separately from the program itself.
Is there a way to bundle Python programs and the assets they use into single-click applications?
Note that I am using Python 3 on Linux Mint. I am also something of a novice, so don't be surprised if I'm missing something obvious here.
It appears I've solved my own problem.
Instead of having the images included in the same folder as main.py and using the resulting short relative filepath to reach them, install the images in an appropriate space in the system directory tree (I used /home/$USER$/.$PROGRAMNAME$/) and have the program access the files using the absolute path to that directory. This will allow you to copy the program anywhere on your computer you want and have it run without a problem.
However, if you want to share it with someone else, you'll need to also include an installation script that places the assets in the correct directory on their computer.
I've just downloaded VSC, because I wanted to edit all my code in one editor (I'm writing in C, Python and HTML). On my computer I have a folder (Programming), in which I have 3 sub-folders (C, Python, HTML). So when I started up VSC I opened this Programming folder, and also downloaded the necessary extensions for python and C in VSC.
Here comes my problem: if I run for example a .py which generates a .txt file, it's not generated in the same location as the .py file is, however in the main folder (programming). Also this issue occurs, when I build an .exe from a .c, it also builds in the main folder and not where my .c is.
Thank you for your help!
The default cwd(current working directory) is the folder you open, like you can see:
Even the script_2.py is under VSCODE\Python\Too\b_folder, its cwd is still under the folder VSCODE and not the specific project.
We can change cwd by the method os.chdir() in the file:
OR the second way, add "python.terminal.executeInFileDir": true, in settings.json
These are some workarounds, and it's still recommended that you turn to the specific project and go on development.
When I have a python project in VS 2017 and create a new python package (folder and __init__.py file) with the "Add->New File" menu, everything works as intended: IntelliSense recognized the package, I can import and use it.
But if I manually create a folder and __init__.py file, then I can still import and the code works fine, but IntelliSense is not picking up the new module. How can I manually include this existing package into the python project?
Perry Qian-MSFT's answer unfortunately did not work for me (more on that in the comment under his answer), but what did work was the same approach as this answer to How do I add an existing directory tree to a project in Visual Studio?
How to add existing package in Python project in Visual Studio 2017
(for IntelliSense)
It is quite strange and it seems that you have created such folder in its physical path which contains a self-created file called __init__.py, but it works well in my side and I can get the Intellisense from the new module. You can follow my steps:
Step
1) I have created a folder called package 3 and add a file called __init__.py under the physical path manually.
2) then open VS, start the project, right-click on it-->Add-->Existing Folder-->add package 3 into it. Then it will import the package 3 folder and its content into Solution Explorer.
3) if you want to use new module in package 3's __init__.py, you could use import node in init.py(package 3) :
import module1;
In addition, if Intellisense does not work either, you should close VS Instance, delete .vs hidden folder under solution folder, then restart the project again to test it. You can try it several times.
Due to a source control folder structure that is out of my control I have found myself in a situation where I need to keep my source python files in three separate locations up-to-date at all times. I am looking for the cleanest solution to accomplish this without having to resort to hacking it together.
I have all of my primary python source files and my Visual Studio 2012 Python Tools project files in a folder that is not published to the end user, but is managed via source control.
I have all of my python files updated into a separate folder that is published to the end users. Files contained in this folder are not ever executed, only used to publish into final builds.
I have a local folder that these python files will end up in if I download a published build. Unfortunately when executing the main application from the published build, this is the folder that the python files will be executed via.
Obviously this is a simplified explanation of the problem. However my goal is to cleanly be able to save a file while editing in Visual Studio 2012 Python Tools, and have it distribute to PublishFiles, and DestinationFiles. Very similar to how in any C++ project you would have an output directory.
My first reaction to this question would be to not work in this fashion, unfortunately I do not have any control over this situation, only need to develop a solution to the problem.
Thanks!