Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用setup.py安装程序包时出现导入错误_Python - Fatal编程技术网

Python 使用setup.py安装程序包时出现导入错误

Python 使用setup.py安装程序包时出现导入错误,python,Python,我试图运行“python setup.py install”,但遇到了导入错误,即导入错误:没有名为xlrd的模块 此模块xlrd模块在“master_to_json”脚本中导入,但xlrd仍放置在安装函数的安装要求中。 master_to_json.py包含 import xlrd .. def main(): .... .... if __name__ == '__main__': main() setup.py包含: import os import sys import su

我试图运行“python setup.py install”,但遇到了导入错误,即导入错误:没有名为xlrd的模块 此模块xlrd模块在“master_to_json”脚本中导入,但xlrd仍放置在安装函数的安装要求中。 master_to_json.py包含

import xlrd
..
def main():
....
....

if __name__ == '__main__':
    main()
setup.py包含:

import os
import sys
import subprocess
from distutils.dir_util import mkpath
from setuptools import setup, find_packages

from dictionary_tools.tools.dictionary import master_to_json
from dictionary_tools.tools.dictionary  import common
setup(
    name=common.PROGRAM,
    version=common.VERSION,
    packages=find_packages(),
    entry_points={
        'console_scripts': [
            master_to_json.__program__ + ' = dictionary_tools.tools.dictionary.master_to_json:main',
        ]
    },
install_requires=["xlrd >= 0.9.2", "xlwt >= 0.7.5"],
long_description=open('README.txt').read()
)
当执行为

$ python setup.py install

问题是,您试图更早地将
master\u导入到\u json
,然后执行setup()

import os
import sys
import subprocess
from distutils.dir_util import mkpath
from setuptools import setup, find_packages

from dictionary_tools.tools.dictionary import master_to_json # <- here is the problem
from dictionary_tools.tools.dictionary  import common
导入操作系统
导入系统
导入子流程
从distutils.dir\u util导入mkpath
从setuptools导入设置中,查找\u包

从dictionary_tools.tools.dictionary import master_to_json#导入
master_to_json
,在实际安装xlrd之前,它会导入
xlrd
,因此它找不到它。您必须在导入它之前安装xlrd