简体   繁体   中英

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

如何将现有Python文件导入/添加到PyCharm项目?

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 .

我不确定我是否得到你想要的东西,但是你可以将现有的源添加到项目中:文件 - >设置 - >项目结构 - >添加内容根 - >选择包含现有代码的文件夹

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.

PS 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM