Unable to mark a directory as test sources root in PyCharm - intellij-idea

I was trying to mark a directory as test sources root in PyCharm so that I don't have to manually set the target directory for my generated test file every time. When I right-click my "tests" directory I only see the following four options:
Mark Directory As:
1. Source Root
2. Template Folder
3. Excluded
4. Resource Root
I remember doing this in Intellij for Java but is this not possible for PyCharm?

Do the following:
Mark the directory as "sources".
Close PyCharm.
Open the <project root>/.idea/<projectname>.iml file in a text editor.
Search for "isTestSource=" for the appropriate directories and change it from "false" to "true".
Reopen PyCharm.

To keep the UI simpler, the test source root configuration option is not exposed in the PyCharm UI.

In PyCharm 2017.1.3
From the tests toolbar, click edit configurations then you can set the working directory default, this will be used by each test on first run.
Hope this helps!

Related

How to add custom directory to "Tests" scope in Intellij IDEA?

I'm working with Ant project, where I've added "test" directory near "src" directory. IDEA does not understand, that all classes in this directory are test classes. I want to make IDEA understand this, so it will propose to generate "Test Method", in respective "Generate" menu, for example, like it does in Maven's test directory. So, how can I make it happen?
Found out how to make it. The user has to open File -> Project structure -> Modules -> Sources Tab, select the directory he wants to make test directory and mark it as test directory using "Tests" button above directory tree.
It works in Intellij IDEA 2016.

Force IntelliJ to use another Home Directory?

I have read this... it does not answer the question.
I would like to have IntelliJ use another location for all of my project files. Currently, it goes to c:\users\ as a default project location.
I want to change that to c:\git.
I tried to change the "Start in" link properties, to no avail.
I don't want to force all of the configuration (ie: the .IdeaIC15 folder) to be relocated, I just want it to go to c:\git when I click "Open project".
To change the directory where project files are located to C:\git:
Select Help->Edit Custom VM Options...
Add the following line to the end of the file that comes up in the editor (*):
-Duser.home=C:\git
Restart IntelliJ.
(*) The file that comes up in the editor will either be idea64.exe.vmoptions or idea.exe.vmoptions.
Notes:
This will update/create a .vmoptions file in your config directory. It does not modify the vmoptions file in your install directory.
The above steps do not change the default directory that is used
when cloning git repositories. This is the directory that is used in
the File->New->Project from Version Control->Git window. You
still need to set that directory to C:\git and clone one remote repo
into C:\git. Once you have done that IntelliJ remembers the directory and
uses it for subsequent clones.
https://intellij-support.jetbrains.com/hc/en-us/articles/207240985-Changing-IDE-default-directories-used-for-config-plugins-and-caches-storage
Locations can be changed by editing the following file:
IDE_HOME\bin\idea.properties
Follow the comments in idea.properties file to change the defaults, make sure to un-comment the lines defining these properties:
idea.config.path
idea.system.path
idea.plugins.path
idea.log.path

Can't see project folders in IntelliJ IDEA

Every once in a while, I open an old project and I can't see any of the folders in the intelliJ project viewer. I can see all the files at the root.. but no folders. Yes I can delete the .iml file and .idea folder and re-create the project, but come on.. there's gotta be an easier way to fix this.
Is there?
If you look in project settings (ctrl-shift-alt-s), you should see a module structure. If you instead see "Nothing to see", do the following:
In Project Structure -> Modules, press the + button,
press enter (since, for some weird reason, it won't let me click on "New Module")
In the window that pops up, click on the "..." next to Content root, find your root folder, and select it
Press ok
ignore any warning that says the name is already in use (or to that effect)
the simplest solution worked from me, just delete the .idea folder
keep in mind this will delete all of idea's current project configuration, it'll create the folder with default settings when reload the project again... but all other configuration will be lost if not properly backed-up
It might be because the project didn't have any modules defined. Try adding existing source code by hitting File > New > Module from Existing Sources and select the parent directory of the project for source code
Go to pom.xml file -> right click -> maven -> generate source and update folders. You will see your files and folder structures in left hand side.
All the project-specific settings for a project opened through Intellij IDE are stored in the .idea folder.
The .idea folder (hidden on OS X) in the solution root contains
IntelliJ’s project-specific settings files. These include per-project
details such as VCS mapping and run and debug configurations, as well
as per-user details, such as currently open files, navigation history
and currently selected configuration.
So, if you are not able to see the project file structure in your Intellij IDE, just delete the .idea folder,
rm -rf .idea
and reload the project, then after reload you'll be easily able to get your project structure displayed.
Thank you very much. I just remove the .idea folder and works in my case.
rm -rf .idea
For me, the java folder was not showing up. I went into File->Project Structure. In the second column, I selected on _main. In the third column, I selected the tab "sources". In what I call the fourth column, where the "+Add Content Root" is shown, I verified, the java source/folder was present. In my case, there was an extra source folder, which was the current location. I removed this, applied and the java folder immediately showed up.
Right click on the Project name -> Open Module Setting -> Check the application context path set it up at your project location.
Check your idea.log -- it may have some details explaining why or what is happening (Help | Reveal log in Explorer). Possibly one of the config files got corrupted.
You can always backup and delete .idea subfolder (project settings) and re-create project from scratch. When it's wroking again (after basic configuration) you may copy some of the files from that folder back to recover some of your settings (if there were many).
This happened to me on a new computer when I opened up a Java project in the newly installed Intellij.
The problem was that I had not installed any JDK on the machine.
I had to install a JDK and then go into the settings at ctrl-shift-alt-s and add a JDK by specifying the folder where I installed it. It's possible that IntelliJ would have found it if I closed it and reopened it.
In my case the solution was to create a new project, specifying the project type and creating it within the same directory path as the project that does not load the project files correctly.
PhpStorm automatically detects that the directory exists and gives you the option to create project from existing sources.
This can be found under:
File --> New project...
For gradle users: "Reload All Gradle Projects" option should help.

Location for install.rdf

I am trying to write a plug-in for selenium UI and following this tutorial. Below is an excerpt from this.
First, what you need is an ‘install.rdf’ file and is located in the
root dir of your workspace
I am not sure what is root directory of workspace here mean. So I have firefox and selenium installed on my computer. Where exactly should I create this install.rdf
The root directory mentioned here is the root directory of the IDE source code. You can download IDE src code from location given below and put the install.rdf in the root.
Selenium IDE src code
Once you have made changes to the plugin src as per your needs. You can build it and install the .xpi hence built to your firefox instance like a regular extension and test it.

How to configure custom PYTHONPATH with VM and PyCharm?

I am using IntelliJ with the Python plugin and the Remote Interpreter feature to communicate with my Vagrant VM. It sets up the remote interpreter correctly to use my VM's interpreter. But, I use a custom PYTHONPATH in my VM, and I would like IntelliJ to recognize that path and include the modules in that path when developing.
How do I configure IntelliJ/PyCharm's remote interpreter to use a custom PYTHONPATH on the VM?
For PyCharm 5 (or 2016.1), you can:
select Preferences > Project Interpreter
to the right of interpreter selector there is a "..." button, click it
select "more..."
pop up a new "Project Interpreters" window
select the rightest button (named "show paths for the selected interpreter")
pop up a "Interpreter Paths" window
click the "+" buttom > select your desired PYTHONPATH directory (the folder which contains python modules) and click OK
Done! Enjoy it!
Instructions for editing your PYTHONPATH or fixing import resolution problems for code inspection are as follows:
Open Preferences (On a Mac the keyboard short cut is ⌘,).
Look for Project Structure in the sidebar on the left under Project: Your Project Name
Add or remove modules on the right sidebar
EDIT: I have updated this screen shot for PyCharm 4.5
To me the solution was to go to
Run > Edit Configuration > Defaults > Python
then manage the
"Add content roots to PYTHONPATH" and
"Add source root to PYTHONPATH"
checkboxes, as well as setting the "Working directory" field.
If you have set up your own Run/Debug Configurations then you might want to go to
Run > Edit Configuration > Python > [Whatever you called your config]
and edit it there.
My problem was that I wanted to have my whole repository included in my PyCharm 2016.2 project, but only a subfolder was the actual python source code root. I added it as "Source Root" by right clicking the folder then
Mark directory as > Source Root
Then unchecking "Add content roots to PYTHONPATH" and checking "Add source root to PYTHONPATH" in the Run/Debug config menu. I then checked the folder pathing by doing:
import sys
logger.info(sys.path)
This outputed:
[
'/usr/local/my_project_root/my_sources_root',
'/usr/local/my_project_root/my_sources_root',
'/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/usr/lib/python3.4/lib-dynload',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages'
]
However, without the fix it said:
[
'/usr/local/my_project_root/my_sources_root',
'/usr/local/my_project_root', <-- NOT WANTED
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/usr/lib/python3.4/lib-dynload',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages'
]
Which meant I got the project root folder included. This messed up the pathing for me.
This was done with PyCharm Community 2019.1
Go to Project Settings
Go to Project Structure and right click on the directory you want to add and click "Sources"
This should add the directory to your pythonpath
An update to the correct answer phil provided, for more recent versions of Pycharm (e.g. 2019.2).
Go to File > Settings and find your project, then select Project Interpreter. Now click the button with a cog to the right of the selected project interpreter (used to be a ...).
From the drop-down menu select Show All... and in the dialog that opens click the icon with a folder and two sub-folders.
You are presented with a dialog with the current interpreter paths, click on + to add one more.
In my experience, using a PYTHONPATH variable at all is usually the wrong approach, because it does not play nicely with VENV on windows. PYTHON on loading will prepare the path by prepending PYTHONPATH to the path, which can result in your carefully prepared Venv preferentially fetching global site packages.
Instead of using PYTHON path, include a pythonpath.pth file in the relevant site-packages directory (although beware custom pythons occasionally look for them in different locations, e.g. enthought looks in the same directory as python.exe for its .pth files) with each virtual environment. This will act like a PYTHONPATH only it will be specific to the python installation, so you can have a separate one for each python installation/environment. Pycharm integrates strongly with VENV if you just go to yse the VENV's python as your python installation.
See e.g. this SO question for more details on .pth files....
Latest 12/2019 selections for PYTHONPATH for a given interpreter.
Well you can do this by going to the interpreter's dialogue box. Click on the interpreter that you are using, and underneath it, you should see two tabs, one called Packages, and the other called Path.
Click on Path, and add your VM path to it.
In pycharm 5 follow this,
https://www.jetbrains.com/pycharm/help/configuring-python-interpreter-for-a-project.html
1)Open the Settings dialog box, and click Project Interpreter page.
2)In the Projects pane, choose the desired project.
3)For the selected project, choose SDK from the list of available Python interpreters and virtual environments.
In Intellij v2017.2 you can go to:
run > edit configurations > click ... next to the field 'Environment variables' > click the green + sign
Name= PYTHONPATH
value= your_python_path
Pycharm 2020.3.3 CE ZorinOS(Linux) File>Settings > Project Structure > {select the folder} > Mark as Source(blue folder icon) > Apply
To verify:
import sys
print(sys.path)
Selected path should be listed here.