Python 为什么pip安装使用的参数有时与导入使用的参数不同?

Python 为什么pip安装使用的参数有时与导入使用的参数不同?,python,pip,Python,Pip,对于许多python库,与导入一起使用的参数与使用pip安装库时使用的参数相同 例如 pip安装numpy pip安装scipy 安装熊猫 对应 导入numpy 进口西皮 进口大熊猫 但这种模式似乎并不适用于所有的库。例如(发现): pip安装枕 要使这项工作取得成功,必须具备以下条件: 导入PIL 根据第一个示例中的模式,我希望pip-install-PIL安装PIL,但我们使用pip-install-PIL。这是为什么?它是如何工作的?基本上,您导入的通常是模块名。例如,您的包可能在

对于许多python库,与导入一起使用的参数与使用pip安装库时使用的参数相同

例如

pip安装numpy
pip安装scipy
安装熊猫
对应

导入numpy
进口西皮
进口大熊猫
但这种模式似乎并不适用于所有的库。例如(发现):

pip安装枕
要使这项工作取得成功,必须具备以下条件:

导入PIL

根据第一个示例中的模式,我希望
pip-install-PIL
安装
PIL
,但我们使用
pip-install-PIL
。这是为什么?它是如何工作的?

基本上,您导入的通常是模块名。例如,您的包可能在以下层次结构中开发:

MyLib
- __init__.py
- my_script1.py
- my_script2.py
但是,当您在
pip
中将库作为“软件包”提供时,通常需要准备
setup.py
文件,当人们使用
pip install
安装您的软件包时,该文件将自动运行

setup.py
可以是这样的:

from distutils.core import setup
setup(
  name = 'YOURPACKAGENAME',         # How you named your package folder (MyLib)
  packages = ['YOURPACKAGENAME'],   # Chose the same as "name"
  version = '0.1',      # Start with a small number and increase it with every change you make
  license='MIT',        # Chose a license from here: https://help.github.com/articles/licensing-a-repository
  description = 'TYPE YOUR DESCRIPTION HERE',   # Give a short description about your library
  author = 'YOUR NAME',                   # Type in your name
  author_email = 'your.email@domain.com',      # Type in your E-Mail
  url = 'https://github.com/user/reponame',   # Provide either the link to your github or to your website
  download_url = 'https://github.com/user/reponame/archive/v_01.tar.gz',    # I explain this later on
  keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'],   # Keywords that define your package best
  install_requires=[            # I get to this in a second
          'validators',
          'beautifulsoup4',
      ],
  classifiers=[
    'Development Status :: 3 - Alpha',      # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
    'Intended Audience :: Developers',      # Define that your audience are developers
    'Topic :: Software Development :: Build Tools',
    'License :: OSI Approved :: MIT License',   # Again, pick a license
    'Programming Language :: Python :: 3',      #Specify which pyhton versions that you want to support
    'Programming Language :: Python :: 3.4',
    'Programming Language :: Python :: 3.5',
    'Programming Language :: Python :: 3.6',
  ],
)
因此,在上面的示例中,通过
pip
安装您的软件包的人应该运行
pip安装您的PackageName
。之后,他们需要在代码中运行
import MyLib

运输署;DL:

导入的是模块名称,但通过
pip
安装的是软件包的名称,它们可以不同。但通常,我会说,我喜欢人们使用相同的名字,以避免任何混淆

参考:

来自枕头文档:
枕头是Alex Clark和贡献者的友好PIL叉子。PIL是Fredrik Lundh和贡献者开发的Python图像库。
。包裹本身被称为枕头,但实际上是PIL叉子。这就是你们进口PIL的原因。谢谢,很好的解释!有没有办法找到包名(与pip一起使用)?例如,我需要运行
导入接收5h
,但
错误:未找到接收5h
的匹配分布。通过
PIL
我可以通过谷歌搜索找到包名,谢天谢地,其他人也有同样的问题。但是使用
inception5h
我无法轻松找到包名。有办法吗?也许有,但我真的不知道。我以前也遇到过同样的问题,我会说只要谷歌一下:)试试谷歌
install sklearn
你就会明白我的意思。