PyCharm 和 PYTHONPATH [英] PyCharm and PYTHONPATH

查看:84
本文介绍了PyCharm 和 PYTHONPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PyCharm 的新手.我有一个用于 PYTHONPATH 的目录:c:\test\my\scripts\.在这个目录中,我导入了一些模块.它在我的 Python shell 中运行良好.

I am new to PyCharm. I have a directory that I use for my PYTHONPATH: c:\test\my\scripts\. In this directory I have some modules I import. It works fine in my Python shell.

如何将此目录路径添加到 PyCharm 以便我可以导入该目录中的内容?

How do I add this directory path to PyCharm so I can import what is in that directory?

推荐答案

数据不足,请看下面 Duane 的回答.

您需要转到Main PyCharm 首选项,这将打开一个单独的窗口.在左窗格中,选择项目:... > 项目解释器.现在,在右侧的主窗格中,单击项目解释器"字段旁边的设置符号(齿轮符号).在弹出的菜单中选择更多全部显示.现在在最后一步中,选择您正在用于该项目的解释器并单击窗口底部的树符号(将鼠标悬停在该符号上会显示为显示所选解释器的路径").通过单击加号"符号添加您的路径.

You need to go to the Main PyCharm Preferences, which will open up a separate window. In the left pane, choose Project:... > Project Interpreter. Now, in the main pane on the right, click the settings symbol (gear symbol) next to the field for "Project Interpreter". Choose More or Show All in the menu that pops up. Now in the final step, pick the interpreter you are using for this project and click on the tree symbol at the bottom of the window (hovering over the symbol reveals it as "Show paths for the selected interpreter"). Add your path by click in the "plus" symbol.

我花了很长时间才找到,所以我希望详细的说明会有所帮助.PyCharm 文档.

It took me ages to find, so I hope the detailed instructions will help. Further details are available in the PyCharm docs.

在您要添加的模块的每个子文件夹中都有 __init__.py 是一种很好的做法,并将您的项目文件夹设为源根目录".只需右键单击路径栏中的文件夹,然后选择将目录标记为..."

It is good practice to have __init__.py in each subfolder of the module you are looking to add, as well as making your project folder a 'Source Root'. Simply right-click on the folder in the path bar and choose 'Mark Directory as ...'

这篇关于PyCharm 和 PYTHONPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆