idea python插件地址_IntelliJ Python插件&运行classpath

I have a project located at /home/myself/workspace/Project1, for which I created an SDK from a Python 2.7.3 Virtualenv I have setup.

This project uses some external code that I have in an accessible directory, e.g. /home/myself/LIBRARY; this directory contains several directories with code, docs etc....

For example, there is a module "important_util" located at /home/myself/LIBRARY/mymodule/important_util.py.

Now, I added the whole dir /home/myself/LIBRARY in the SDK Classpath, and in the Editor window it appears just fine. The imports and calls are recognized and I can also navigate through the code in LIBRARY directories.

The problem is that, when I try to run my program, it fails at the first import using LIBRARY!!!

Traceback (most recent call last):

File "/home/myself/workspace/Project1/my_program.py", line 10, in

from mymodule import important_util as ut

ImportError: No module named mymodule

I also tried to add the same directories to the section "Global Libraries" in the Sources section...but no luck.

I can't seem to find a way to add this code to the Run classpath, how would I be able to do this?

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值