How do I import/add an existing Python file to a PyCharm project?
Solution 1
Copy the files to some directory under the project root using your favorite file manager or add the directory containing your files to the project using Settings
(Preferences
on Mac) | Project Structure
| Add Content Root.
Solution 2
I'm not sure if I get what you want, but there's way you can add existing source into project: File -> Settings -> Project structure -> Add Content root -> choose folder with existing code
Solution 3
I hacked this way - copy files into another folder, create new files with the same names using IDE, and replace the new files with the copied versions. It does the trick.
P.S. I grepped .idea
folder and found no project file like CMakeLists.txt
to edit manually. There are numerous entries in the .idea/workspace.xml
file, but I am not sure how to generate proper entries by hand.
Comments
-
LostMohican almost 2 years
How do I import/add an existing Python file to a PyCharm project?
-
tumultous_rooster over 10 yearsWhat would happen if I wanted to just include one particular file in the project structure?
-
minghua about 10 years@matt, I have not seen an IDE which does that. Please share if you known of a solution other than copying files or making soft-links or hard-links in os.
-
Jean-Denis Muys almost 9 yearsWell, Xcode, for one, does that. This is a difficult to understand Pycharm's limitation. I have been struggling with this issue for too long
-
Skulas over 6 yearsIn visual studio you can also import files from anywhere. On build time all the files are copied to your build output folder.
-
Harry over 3 yearsIn PyCharm 2020.2, there is no
Settings
menu bar item. It looks like this can now be found underFile
|Settings
|Project: <project name>
|Project Structure
| Add Content Root. -
Emir over 2 yearsIn PyCharm 2021.2, Linux, this setting no longer exists (if it ever did). There is no Project/Project Structure under settings. Things like this are such a frustrating experience with PyCharm that I end up going back to vim or Jupyter-lab for editing. I mean, wouldn't importing code files be one of the most basic usecases? There are tons of useless buttons for things like expanding and contracting the project view but not for adding in files.