Python3无法导入argcomplete包

时间:2018-05-27 12:10:44

标签: python python-3.x

我试图导入" argcomplete"包裹,但我面临以下错误:

$ python3
Python 3.6.3 (v3.6.3:2c5fed86e0, Oct  3 2017, 00:32:08) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import argcomplete
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'argcomplete'
>>> exit()

我确认已成功安装argcomplete:

#pip3 install argcomplete
Collecting argcomplete
Using cached https://files.pythonhosted.org/packages/31/88/ba8d8684a8a27749250c66ff7c2b408fdbc29b50da61200338ff9b2607bf/argcomplete-1.9.4-py2.py3-none-any.whl

Installing collected packages: argcomplete
Successfully installed argcomplete-1.9.4

$ more test_backend.py 
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
"""
Run module with test data
"""

$ cd /usr/local/lib/python3.6/site-packages/
apple site-packages
$ ls -ltrh arg*
-rw-r--r--  1 apple  admin    87K May 27 03:34 argparse.py

argcomplete-1.9.4.dist-info:
total 104
-rw-r--r--  1 apple  admin    12B May 27 15:38 top_level.txt
-rw-r--r--  1 apple  admin   1.5K May 27 15:38 metadata.json
-rw-r--r--  1 apple  admin   110B May 27 15:38 WHEEL
-rw-r--r--  1 apple  admin   2.0K May 27 15:38 RECORD
-rw-r--r--  1 apple  admin    16K May 27 15:38 METADATA
-rw-r--r--  1 apple  admin     4B May 27 15:38 INSTALLER
-rw-r--r--  1 apple  admin    14K May 27 15:38 DESCRIPTION.rst

argcomplete:
total 160
-rw-r--r--  1 apple  admin   2.1K May 27 15:38 shellintegration.py
-rw-r--r--  1 apple  admin    13K May 27 15:38 my_shlex.py
-rw-r--r--  1 apple  admin    15K May 27 15:38 my_argparse.py
-rw-r--r--  1 apple  admin   3.6K May 27 15:38 completers.py
-rw-r--r--  1 apple  admin   524B May 27 15:38 compat.py
 drwxr-xr-x  3 apple  admin   102B May 27 15:38 bash_completion.d
-rw-r--r--  1 apple  admin   1.4K May 27 15:38 _check_module.py
drwxr-xr-x  9 apple  admin   306B May 27 15:38 __pycache__
-rw-r--r--  1 apple  admin    29K May 27 15:38 __init__.py

/usr/local/lib/python3.6/site-packages/已添加到PATH

我注意到import只能在目录/usr/local/lib/python3.6/site-packages中工作,但不能从其他地方工作

$ python3 -c 'import argcomplete'
>> successful


$ cd /Users/apple/Desktop/XXXXX/
apple (master) XXXXX
$ python3 test_backend.py 
Traceback (most recent call last):
  File "test_backend.py", line 11, in <module>
    import argcomplete
ModuleNotFoundError: No module named 'argcomplete'
apple (master) XXXXX
$ python3 -c 'import argcomplete'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'argcomplete'
apple (master) XXXXX

请告知如何解决此问题,谢谢。

2 个答案:

答案 0 :(得分:1)

尝试运行以下命令在python3中安装argcomplete

在终端:

python3

在Python3控制台中:

import pip

def install(package):
    pip.main(['install', package])


install('argcomplete')

然后尝试在python控制台中使用argcomplete完整包。

答案 1 :(得分:1)

问题是python 2.7是mac的默认设置,因此通过终端安装包只会在python 2.7上安装它们。

如果您已经在版本3上安装了pip,请执行以下操作:

wp_enqueue_style