确认安装后没有名为

确认安装后没有名为

本文介绍了Python ImportError:确认安装后没有名为"requests"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,并在终端中进行了一些设置,现在正尝试在Atom中运行python代码.

I'm new to python and set up a few things in terminal and am now trying to run python code in Atom.

我在代码编辑器中的前三行是:

My first three lines in my code editor are:

import re
import requests
import robobrowser

运行代码时,我不断得到

When I run the code I keep getting the

我假设这与文件的路径或位置有关,但是我不确定如何检查.

I'm assuming it has to do with the path or placement of my files, but I'm not sure how to check that.

我正在终端中运行的版本:

Versions I'm running in terminal:

(prot) MacBook:prot myname$ python --version
Python 3.7.3
(prot) MacBook:prot myname$ pip --version
pip 19.0.3 from /Users/myname/prot/prot/lib/python3.7/site-
packages/pip (python 3.7)

我还使用以下方法创建了一个虚拟环境:

I also created a virtual env using the following:

MacBook:prot myname$ python3 -m venv prot
MacBook:prot myname$ source prot/bin/activate

所以我的默认命令行显示为:

So my default command line displays:

运行以下命令显示所需的软件包已存在.

Running the following shows that the needed packages are there.

(prot) MacBook:prot myname$ pip3 list
Package        Version
-------------- --------
beautifulsoup4 4.7.1
certifi        2019.3.9
chardet        3.0.4
idna           2.8
pip            19.0.3
requests       2.21.0
robobrowser    0.5.3
setuptools     40.8.0
six            1.12.0
soupsieve      1.9
urllib3        1.24.1
Werkzeug       0.15.1

编辑(根据评论进行更新):

import sys
print(sys.version)

在Atom输出中(用于说2.#,所以我在atom中更新了版本):

in Atom outputs (used to say 2.#, so I updated the version in atom):

[与GCC 4.2.1兼容的Apple LLVM 10.0.0(clang-1000.0.42)]

[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)]

Robobrowser正确显示在终端中:

Robobrowser shows up in terminal correctly:

(prot) MacBook:prot myname$ pip3 show robobrowser
Name: robobrowser
Version: 0.5.3
Summary: Your friendly neighborhood web scraper
Home-page: https://github.com/jmcarp/robobrowser
Author: Joshua Carp
Author-email: [email protected]
License: MIT
Location: /Users/myname/prot/prot/lib/python3.7/site-packages
Requires: beautifulsoup4, requests, six, Werkzeug
Required-by:

要检查剩余的robobrowser问题,我在原子中运行了此

To check the remaining robobrowser issue, I ran this in atom:

from pip import _internal
_internal.main(['list'])

并收到了此消息(注意缺少robobrowser):

and got this (notice robobrowser is missing):

Package         Version
--------------- --------
cached-property 1.5.1
certifi         2019.3.9
chardet         3.0.4
idna            2.8
pip             19.0.3
python-dateutil 2.8.0
requests        2.21.0
setuptools      40.8.0
six             1.12.0
urllib3         1.24.1
wheel           0.33.1

在终端中运行

pip show requests
pip show robobrowser

返回相同的位置

在原子中运行

import sys
print(sys.path)

输出

所以我想我需要将以上位置添加到sys.path

So I think I need to add the above location to the sys.path

推荐答案

我解决了问题,但不确定是否以正确的方式进行了操作.我退出venv,然后回到我的主目录.安装的robobrowser然后回到我正在处理的特定venv/目录中.这解决了我的问题.

I solved the problem although not sure if I did so the proper way. I exited the venv and went back to my main directory. Installed robobrowser then went back into the specific venv/directory I was working out of. This solved my issue.

这篇关于Python ImportError:确认安装后没有名为"requests"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:23