How do I import/add an existing Python file to a PyCharm project?

PythonProjectPycharm

Python Problem Overview


How do I import/add an existing Python file to a PyCharm project?

Python Solutions


Solution 1 - Python

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 - Python

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 - Python

For PyCharm 2017 (v.2017.2.3), it's slightly different. You still need to copy the files you want to add to a directory under the project's own root directory, but they don't appear in the Project navigation window in PyCharm immediately. To correct this, click on the Project's name in the Navigation window to collapse the project's tree structure, then open it up again. You should now be able to see the files you've just added.

Solution 4 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLostMohicanView Question on Stackoverflow
Solution 1 - PythonCrazyCoderView Answer on Stackoverflow
Solution 2 - PythonyedpodtrzitkoView Answer on Stackoverflow
Solution 3 - Pythonuser7772648View Answer on Stackoverflow
Solution 4 - Pythondmitry_romanovView Answer on Stackoverflow