How do I import/add an existing Python file to a PyCharm project?
如何将现有Python文件导入/添加到PyCharm项目?
3 个解决方案
#1
43
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.
使用您喜欢的文件管理器将文件复制到项目根目录下的某个目录,或使用设置(Mac上的首选项)将包含文件的目录添加到项目中。项目结构|添加内容根。
#2
21
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
我不确定我是否得到你想要的东西,但是你可以将现有的源添加到项目中:文件 - >设置 - >项目结构 - >添加内容根目录 - >选择包含现有代码的文件夹
#3
1
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.
我这样攻击 - 将文件复制到另一个文件夹,使用IDE创建具有相同名称的新文件,并用复制的版本替换新文件。它成功了。
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.
附:我grepped .idea文件夹,发现没有像CMakeLists.txt这样的项目文件可以手动编辑。 .idea / workspace.xml文件中有许多条目,但我不确定如何手动生成正确的条目。
#1
43
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.
使用您喜欢的文件管理器将文件复制到项目根目录下的某个目录,或使用设置(Mac上的首选项)将包含文件的目录添加到项目中。项目结构|添加内容根。
#2
21
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
我不确定我是否得到你想要的东西,但是你可以将现有的源添加到项目中:文件 - >设置 - >项目结构 - >添加内容根目录 - >选择包含现有代码的文件夹
#3
1
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.
我这样攻击 - 将文件复制到另一个文件夹,使用IDE创建具有相同名称的新文件,并用复制的版本替换新文件。它成功了。
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.
附:我grepped .idea文件夹,发现没有像CMakeLists.txt这样的项目文件可以手动编辑。 .idea / workspace.xml文件中有许多条目,但我不确定如何手动生成正确的条目。