python如何安装本地包_如何点子安装本地python包?

Question

I installed a local package called credentials using

pip install -e c:\users\worker\src\clockwork\lib\credentials

But when I try to import the package from a sibling directory, it fails with an ImporError:

cd c:\users\worker\src\clockwork\bank

python -c "import credentials"

...

ImportError: No module named 'credentials'

Confusingly, the package credentials is listed as successfully installed as shown when I run pip list:

...

credentials (1.0.0, c:\users\worker\src\clockwork\lib\credentials)

...

How can I install my local package so that it can be imported?

Background

I am using Python 3.4 (32-bit). The package contains two files:

credentials\__init__.py

credentials\setup.py

The __init__.py file defines a single function. The setup.py file is short:

from distutils.core import setup

setup(name='credentials', version='1.0.0')

Workaround

I currently add the directory containing the package (c:\users\worker\src\clockwork\lib) to my PATH variable as a workaround. But my question is how to install the package properly so that I do not need to modify the PATH.

解决方案

The problem centers on setup.py. It needs to declare a package:

from distutils.core import setup

setup(name='credentials', version='1.0.0', packages=['credentials'])

But this setup.py must be in the parent directory of the credentials package, so in the end, the directory structure is:

...\credentials\setup.py

...\credentials\credentials\__init__.py

With this change, the module is found after reinstalling the package.

This could also be caused by two Python installs (but wasn't in my case), and @Mr_and_Mrs_D gives an answer for that case.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值