Heyo!我知道这可能看起来像this question的重复问题,但有一点不同。我想导入整个包,而不仅仅是一个或一组函数。当我从Anaconda导入包,并尝试将它们导入python脚本时,我得到ErrorModuleNotFound
。我可能导入了这个错误,所以这里是信息:
Python 3.6
和conda 4.3.21
。C:\ProgramData\Miniconda3
pip install wikipedia
(它成功安装......)C:\Users\aglin\Desktop\test.py
root * C:\ProgramData\Miniconda3
C:\Users\aglin\AppData\Local\Programs\Python\Python36-32\python.exe
和C:\ProgramData\Miniconda3\python.exe
的路径我的Python脚本包含的内容:
import wikipedia
print (wikipedia.summary("Windows OS"))
win = wikipedia.page("New York")
win.content
我得到的错误:
================== RESTART: C:\Users\aglin\Desktop\test.py ==================
Traceback (most recent call last):
File "C:\Users\aglin\Desktop\test.py", line 1, in <module>
import wikipedia
ModuleNotFoundError: No module named 'wikipedia'
我的问题:如何在不收到此错误的情况下导入包wikipedia
?如果有帮助,可以找到“维基百科API for Python的文档”here。另外,我对Python很新,所以如果我需要做任何具体的工作或查看文档,请告诉我。谢谢! :d
以下是在conda中创建环境,将Python版本放入其中,以及之后将库导入其中的常用步骤。
步骤是:
您会注意到,在显示结束时,可以打开Python解释器并导入维基百科。
Microsoft Windows [Version 10.0.16299.125]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\scratch>conda create --name Py36 python=3.6
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment C:\ProgramData\Miniconda3\envs\Py36:
The following NEW packages will be INSTALLED:
certifi: 2017.11.5-py36hb8ac631_0
pip: 9.0.1-py36h226ae91_4
python: 3.6.3-h3b118a2_4
setuptools: 36.5.0-py36h65f9e6e_0
vc: 14-h2379b0c_2
vs2015_runtime: 14.0.25123-hd4c4e62_2
wheel: 0.30.0-py36h6c3ec14_1
wincertstore: 0.2-py36h7fe50ca_0
Proceed ([y]/n)? y
#
# To activate this environment, use:
# > activate Py36
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
C:\scratch>activate Py36
(Py36) C:\scratch>pip install wikipedia
Collecting wikipedia
Collecting beautifulsoup4 (from wikipedia)
Using cached beautifulsoup4-4.6.0-py3-none-any.whl
Collecting requests<3.0.0,>=2.0.0 (from wikipedia)
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests<3.0.0,>=2.0.0->wikipedia)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests<3.0.0,>=2.0.0->wikipedia)
Using cached idna-2.6-py2.py3-none-any.whl
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\miniconda3\envs\py36\lib\site-packages (from requests<3.0.0,>=2.0.0->wikipedia)
Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0.0,>=2.0.0->wikipedia)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: beautifulsoup4, urllib3, idna, chardet, requests, wikipedia
Successfully installed beautifulsoup4-4.6.0 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 wikipedia-1.4.0
(Py36) C:\scratch>python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 15:10:56) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wikipedia
>>> ^Z
(Py36) C:\scratch>