How to work within individual files rather than projects in PyCharm
Solution 1
On Pycharm 5.0.4...
- Open the file (i.e. by double clicking in explorer)
- Navigate to File->Settings...
- Expand the Project tab on the left and select 'project interpreter' from the options that appear beneath
- Set your project interpreter from the dropdown menu, and you should be able now to run your file without creating a project
Solution 2
You can always open a single file (File > Open) but to actually run or debug the code from within Pycharm, or use most of its other features, it needs a correctly configured project.
What you can do is create a single project to hold all of your "assorted" code. I usually recommend creating a virtualenv for this project as well and using that as your Pycharm project interpreter. You can further divide this project into different packages to keep things organized.
Update: PyCharm 4.5 now provide Scratch Files which seem relevant to this question.
Solution 3
You have to work with a configured project (indicated by folders) but there is a work around... In Pycharm when you create a project you will have a default file in .py or any other format.
Just follow the steps to work with individual files..
right click on the folder (in left hand side project tree) and add new python file
double click on the newly added file ,it will now be open in a new tab
(BUT..if you try to run this new file pycharm will still compile the previous file ...so to change that..)
right click on the tab of your file and click run "file name" or you can press CTRL+shift+F10
done :)
Solution 4
From the command line
pycharm [path_to_your_file]
where pycharm
on my machine is aliased to /opt/pycharm-community-3.1.1/bin/pycharm.sh
in file ~/.bash_aliases
.
As Preston mentioned, not all features seem to work: for example, navigation between files does not seem to work.
Steven Evans
Updated on June 14, 2022Comments
-
Steven Evans about 2 years
Relatively new to Python and PyCharm and as such most of the work. I'm doing is single files and therefore is not organized into projects.
Is there a way to configure Pycharm to be used to open single files and not use projects?
Similarly, is it possible to just run a single page/file?
-
poleguy about 4 yearsFurthermore, their documentation says (jetbrains.com/help/pycharm/opening-files-from-command-line.html) that it will create an .idea directory, but in reality at least on linux it does not, rather creating a directory of /tmp/filename. Tested in 2019.3. It seems a sloppy mess.
-
eric over 3 yearsthis is why I don't use pycharm. too much overhead.
-
gseattle over 3 yearsWorks! For Debug too. This should be the checkmark answer. Right click on the second file tab and that Debug is for it, only, versus the project Debug icon in the upper right. Even though Configuration uses the original file in 'Script path:'. Sure good to know this.