简体   繁体   English

Python: Package目录不存在

[英]Python: Package directory does not exist

I'm trying to install a python package in windows 10 using the following setup.py file.我正在尝试使用以下 setup.py 文件在 windows 10 中安装 python package。

"""Setup file for uhd module"""

from setuptools import setup

setup(name='uhd',
      version='3.14.0',
      description='Universal Software Radio Peripheral (USRP) Hardware Driver Python API',
      classifiers=[
          'Development Status :: 4 - Beta',
          'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
          'Programming Language :: C++',
          'Programming Language :: Python',
          'Topic :: System :: Hardware :: Hardware Drivers',
      ],
      keywords='SDR UHD USRP',
      author='Ettus Research',
      author_email='packages@ettus.com',
      url='https://www.ettus.com/',
      license='GPLv3',
      package_dir={'': 'C:/Users/bcollins/UHD_PY/uhd/host/build/python'}, 
      package_data={'uhd': ['*.so']},
      zip_safe=False,
      packages=['uhd'],
      install_requires=['numpy'])

I execute the script using the command我使用命令执行脚本

python setup.py install

I do this from the directory that contains the setup.py file.我从包含 setup.py 文件的目录执行此操作。

This returns the following error这将返回以下错误

error: package directory 'C:Users\bcollins\UHD_PY\uhd\host\build\python\uhd' does not exist

There is a folder called "uhd" at that location though.不过在该位置有一个名为“uhd”的文件夹。 The folder contains the __init__.py file该文件夹包含__init__.py文件

If the script isn't looking for this folder, what is it looking for?如果脚本不在寻找这个文件夹,它在寻找什么?

I'm not exactly experienced in this area but my best guess is that its looking for a.so file within the "uhd" folder at that location, but I'm not sure.我在这方面并不完全有经验,但我最好的猜测是它在那个位置的“uhd”文件夹中寻找一个 .so 文件,但我不确定。

I am using python 2.7.我正在使用 python 2.7。

package_dir has to be a relative path, not an absolute path. package_dir必须是相对路径,而不是绝对路径。 The distutils layer under setuptools tries to reject absolute paths, but the C: confuses it. setuptools 下的 distutils 层试图拒绝绝对路径,但C:混淆了它。 It ends up converting your path to它最终将您的路径转换为

C:Users\bcollins\UHD_PY\uhd\host\build\python\uhd

Note the missing backslash between C: and Users .注意C:Users之间缺少的反斜杠。 This path is relative to your current working directory on the C drive ( windows drive handling is weird ), and relative to your working directory, this path is invalid.此路径相对于您在 C 驱动器上的当前工作目录( Windows 驱动器处理很奇怪),并且相对于您的工作目录,此路径无效。

This doesn't answer the original question, but it's how I fixed the same error.这不能回答原始问题,但这是我修复相同错误的方式。

I had:我有:

from setuptools import setup, find_packages

setup(
    ...
    packages=find_packages('src', exclude=['test']),
    ...
)

I had added the src argument because my packages are located in src , but it turns out find_packages is smart enough on it's own.我添加了src参数,因为我的包位于src ,但事实证明find_packages就足够智能。

Remove the first argument:删除第一个参数:

from setuptools import setup, find_packages

setup(
    ...
    packages=find_packages(exclude=['test']),
    ...
)

This was on Python 3.5, but I imagine it applies to most other versions.这是在 Python 3.5 上,但我想它适用于大多数其他版本。

我发现当 python 脚本文件夹 (%python_root%\\scripts) 不在环境 PATH 中时,可能会发生此错误。

I had this problem, it turned out that you just need to add a slash after your package directory: packages=['uhd'] should be packages=['uhd/'] .我有这个问题,原来你只需要在你的 package 目录后添加一个斜杠: packages=['uhd']应该是packages=['uhd/']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM