为什么我自己创建的包不在sitepackages中?

2024-05-19 10:23:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习用python创建一个包。这是软件包的结构

funniest
   -- funniest
      -- __init__.py
   -- setup.py

初始化.py

def joke():
    return (u'Wenn ist das Nunst\u00fcck git und Slotermeyer? Ja! ... '
        u'Beiherhund das Oder die Flipperwaldt gersput.')

你知道吗设置.py你知道吗

from setuptools import setup

setup(name='funniest',
      version='0.1',
      description='The funniest joke in the world',
      url='http://github.com/storborg/funniest',
      author='Flying Circus',
      author_email='flyingcircus@example.com',
      license='EXXX',
      packages=['funniest'],
      zip_safe=False)

然后我在文夫做了

source bin/activate
python setup.py develop
python setup.py install

然后我想在venv中使用本地python脚本中的包

from funniest import * // I get error here. ImportError: No module named funniest

但无法在脚本中导入包。所以我去查看了网站包,我看到最有趣的蛋-链接,所有导入都失败。有人能解释为什么它不在站点包中,或者如何让“最有趣”的包在本地可用吗?你知道吗

更新:我也尝试了以下操作,但是我的包没有在输出中列出

yolk -l

Tags: frompyimport脚本comreturninitdef
2条回答

我使用与您的项目相同的结构创建了一个项目:

python setup.py develop
...Processing dependencies for funniest==0.1
...Finished processing dependencies for funniest==0.1

我仔细检查了站点包中的funniest.egg-link,它指向projects/funniest,看起来不错。 然后我做了一个pip list,最有趣的是在列表中

funniest (0.1)

然后我开始python使用相同的python环境,它完全按照预期工作:

(venv) \projects\funniest>python
>>> from funniest import joke
>>> joke.joke()
hi

我创造了笑话.py在projects/funniest/funniest下使用joke()函数。你知道吗

请仔细检查您使用的是相同的python环境。希望有帮助。你知道吗

相关问题 更多 >

    热门问题