按位置导入软件包

问题描述 投票:0回答:1

python-docx上为python3.5安装了ubuntu 16.04程序包。

软件包安装成功,pip3 show python-docx给出:

Name: python-docx
Version: 0.8.10
Summary: Create and update Microsoft Word .docx files.
Home-page: https://github.com/python-openxml/python-docx
Author: Steve Canny
Author-email: [email protected]
License: The MIT License (MIT)
Location: /home/otariki/.local/lib/python3.5/site-packages
Requires: lxml
Required-by: 

然后,我尝试将包导入到我的python文件中,例如:

import sys
sys.path.append('/home/otariki/.local/lib/python3.5/site-packages/docx')
from docx import Document

给出错误:ImportError: No module named 'docx'

我的错是什么?

python python-3.5
1个回答
0
投票

您需要附加/home/otariki/.local/lib/python3.5/site-packages/文件夹。为什么?程序包在文件夹docx中(__init__.py文件表示docx是程序包)。

注意:请注意,默认情况下,$HOME/.local/lib/python3.5/site-packages/文件夹应为PYTHONPATH的一部分。我的意思是:您无需将该文件夹添加到sys.path,它应该由Python自动完成。

© www.soinside.com 2019 - 2024. All rights reserved.