python说没有请求模块_Python ImportError:确认安装后没有名为“ requests”的模块

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

ImportError: No module named robobrowser

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:

(prot) MacBook:prot myname$

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

Edit (updated based on comments):

import sys

print(sys.version)

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

3.7.3 (default, Mar 27 2019, 09:23:15)

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

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:

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

from pip import _internal

_internal.main(['list'])

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

In terminal, running

pip show requests

pip show robobrowser

returns the same Location

/Users/myname/prot/prot/lib/python3.7/site-packages

In atom, running

import sys

print(sys.path)

outputs

['', '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']

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

解决方案

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说没有请求模块)