I have a directory that I use for my PYTHONPATH: c:\test\my\scripts\. In this directory, I have some modules I import. It works well in my Python shell.
How do I add this directory path to PyCharm, so I can import what is in that directory?
Out of data, see Duane's answer below.
You need to go to the Main PyCharm Preferences, which will open up a separate window. In the left pane, choose Project:... > Project Interpreter. Now, in the main pane on the right, click the settings symbol (gear symbol) next to the field for "Project Interpreter". Choose More or Show All in the menu that pops up. Now in the final step, pick the interpreter you are using for this project and click on the tree symbol at the bottom of the window (hovering over the symbol reveals it as "Show paths for the selected interpreter"). Add your path by click in the "plus" symbol.
It took me ages to find, so I hope the detailed instructions will help. Further details are available in the PyCharm docs.
It is good practice to have __init__.py in each subfolder of the module you are looking to add, as well as making your project folder a 'Source Root'. Simply right-click on the folder in the path bar and choose 'Mark Directory as ...'
For Pycharm Community 2019.3
File
Settings
Project
Project Interpreter
Cog in top right => Show all
Select the interpreter
On the right toolbar, there are 5 icons, bottom one looks like a folder tree, click it
Press plus +
Select directory, press OK
In PyCharm Community 2019.2/2019.3 (and probably other versions), you can simply:
right-click any folder in your project
select "Mark Directory As"
select "Sources Root"
Modules within that folder will now be available for import. Any number of folders can be so marked.
The following answer is for PyCharm 2022.1.3+ (Professional Edition).
Open up Preferences (mac: ⌘ + ,)
Click on Project and then Project Interpreter
Click on the three vertical dots and the on Show All...
Choose your interpreter and then click on the directory structure icon
Click on the + icon and add the path you need to add to PYTHONPATH.
That's it!
enter image description here
you can go to setting in pycharm
and set interpreter python
Related
I am using Sublime Text editor and I need to change the settings for Sublime 3 to open files that start with a dot like .gitignore. Please let me know where in the settings I need to make the change. I am using Windows OS fyi.
This isn't a Sublime-specific option, but an operating system one, as the OS determines what is displayed in file dialogs as well as the file system explorer. To set the option on Windows, first open Windows Explorer and navigate to the folder containing the dotfile you want to view. Then, in the View tab, click the Options button on the far right, then select Change folder and search options.
You can also find Options under the File menu.
The Options window will now pop up. Select the View tab, then select the option Show hidden files, folders, and drives. Next, click on the Apply to Folders button at the top.
Similar options are also available on macOS and Linux.
Often I have the case that I have a file opened in the tabs like item_category.xml here:
The project explorer still shows something else. Any way to open the path to item_category.xml in the project explorer? I already checked the right-click menu of item_category.xml, but couldn't find a matching option.
Use that symbol in the project explorer (shortcut: Alt+F1, 1):
More information on the feature: Locate a file in the Project tool window.
If you don't want to use mouse but keyboard shortcut
First option could be assigning a shortcut to Select in Project View may do the trick. It is located under Keymap/Other.
Second option could be to install Scroll From Source plugin for this. The details are here
Set the keyboard shortcut to the function of "Scroll From Source" in Project Panel. You can set the special shortcut by yourself to all OS(Window/Linux/Mac)
Default shortcut is Command + Control + S for Mac.
I have a custom anaconda environment which I am using to run a program which is dependent on files in another directory. How do I add these files to the environment like I would do with a system interpreter by adding the paths to PYTHONPATH variable in system variables?
I did not need to add the custom files to the virtual environment configuration. I was using the Pycharm Python editor and found a better workaround by adding the paths to the selected interpreter (which in this case was the interpreter for the virtual python environment that I was using).
Go to File —>Settings—> Project: Project name—>Project Interpreter
Next to the project interpreter, click the little gear icon.
Click on Show all. A window should pop-up.
On the right side of the window, there’s a toolbar containing 5 options starting with the plus icon.
Click on the last icon with the file symbol. Another window should open.
Here click on the plus symbol on the top right toolbar.
Go to the directory that you want to include to use in your code and click Ok to add them to the interpreter path.
Repeat for any other directories or files that you may need to have.
This solution with Pycharm worked out pretty well for me since I only needed to reference those files on my computer for that particular project.
I am working with Python 3.4.
When I use IDLE and start typing, e.g.,
my_main_folder = "C:/Us"
in the editor window, and then press Ctrl + Space, IDLE offers me all subfolders of C:, and if I press Tab, the string is completed to "C:/Users".
That means that IDLE (or Python Shell) is able to recognize a string as a path.
How to make PyCharm (Community edition) do that?
Its not able in Community Edition Pycharm. But it can be done in Professional Edition Pycharm. I would suggest you to move to Professional Edition.
Does PyCharm have autocomplete file path?
BUT,There is a work around for it in Community Edition.
Place caret in such place and press Alt+Enter -- see if you will have "Inject language or reference" option in appeared menu. If it's present -- use it and choose "File Reference" there.
NOTE 1: this option may not be available if string is empty or has less than 2 characters in it
NOTE 2: this is temp injection -- AFAIK it will be lost after IDE restart (and you will need to do it again if needed)
Otherwise: select desired file in Project View panel and use "Copy Reference" -- it will copy a file path relative to the project root -- you may only need to add leading "/"...
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206574619-Autocompleting-relative-paths
After searching I found this answer:
can we tab through paths, in the same way you can in the terminal?
No, it's not posible:(
I wrote a plugin for Komodo called AutoCode that allowed me to ALT+Click on files in the Project view, and it would automatically resolve the right path
You can use 'Copy reference' in file right-click menu to copy file path relative to project root to clipboard. But this action doesn't unfortunately take resource roots into account
However, you can use CNTRL-SPACE twice and it will present a list of paths and files, example:
For a detailed description of this information see here
Do you know how to check the location of current editing file in the project tree panel (the very left panel of the Android Studio), except manually. (The worst case is that all the folders there are collapsed)
The Navigate->Class shortcut can show me the src file in edit panel (central panel) quickly. Then I want to know the src file's logic location in project tree (left panel), so that I can add some new files in the same package quickly. (e.g. right-click the package and add new Class).
Currently, I have to expand the project tree and find it folder by folder.
Actually, in Xcode there is such a shortcut named "Reveal in Project Navigate"
What a convenient way it is.
I wonder whether this is also supported in Android studio.
Thanks
You can use the Scroll from Source button in the Project Toolbar in the left of Android Studio.
Another solution is Alt+F1+1. You can also read Locate current file in IntelliJ for more answers.
Just enable the following option!
In Android Studio 4 it is now Always Select Opened File under the Settings menu in the project view.
For automatic scrolling, you can do following:
You need to ensure Autoscroll to Source and Autoscroll from source is enabled.
Whenever you change the file the Project tree will be highlighted according.
I have observed some slowness and lag if project size is big(several modules or huge code base) and you use short cut Ctrl + N to navigate to a class.
So the alternative would be to either to click following icon:
OR
Use keyboard shortcut:
Alt + F1 + 1 or Alt + F1 + Enter
You can add shortcut (keymap) to "reveal current editing file in project explorer" command.
Press Ctrl + Alt + S, for Windows user, to open Settings
Select Keymap on the sidebar
Find the command using search box, type this into it: select in project view
Right click the result then select Add Keyboard Shortcut
Type any keyboard combination you want, for example, me prefer shortcut Ctrl + K to reveal current editing file on project explorer
Click OK button. It will prompt you to remove keyboard shortcut you typed from existing command, so just click Remove button.
I'm new to android development. I used to code in Sublime Text 3. One of first thing I do to make android development feels more enjoyable is binding all shortcut I used in Sublime Text 3 to Android Studio. Now, it feels like home :)
For Mac users: Option+fn+F1, then Enter.
Android Studio 3.6.3 (April 2020)
Go to Preferences > Keymap & search for "Select in Project View" and assign your keyboard shortcut.
Under options menu, select Auto scroll from Source
Navigate -> Select In.. -> Project View -> Project
open pref -> Keymap, then search 'select file in project view', not 'select opened file'.