IntelliJ Python plugin & Run classpath

我只是一个虾纸丫 提交于 2019-11-28 21:15:43

Make sure you have __init__.py in mymodule directory:

The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later. ©

UPDATE: In IntelliJ IDEA additional directories should be added as Module Dependencies or configured as Libraries (to be added to the Dependencies) instead of the Classpath tab of the Python SDK:

I've verified that this folder (D:\dev\lib) is added to the PYTHONPATH and import works.

In IntelliJ 14 it's a little different, you are modules/eggs like so:

  • Go to File -> Project Structure
  • Now select Modules and then "Dependencies" tab
  • Click the "+" icon and select "Library"
  • Click "New Library" and select Java (I know it's weird...)
  • Now choose multiple modules / egg and "OK".
  • Select "Classes" from categories.
  • Give your new library a name, "My Python not Java Library"
  • And finally click "Add Selected"

From Version of 2017.1 adding it has been changed again. There is no project structure in the file menu. Writing current procedure down:

  1. Go To Preference/Settings. File -> Settings (IDE Name -> Preferences for macOS)

  2. Select Build, Execution, Deployment

  1. Select Python Interpreter

  2. Select on drop-down menu of project interpreter and select the path of path of version of Python required for the project.

  1. Click on Apply and wait for few minutes to let IntelliJ index the python packages.

All error should be gone now and You should be able to see Python used in the project in the list of external libraries.

Happy Coding.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!