Jack-Cherish / python-spider

:rainbow:Python3网络爬虫实战:淘宝、京东、网易云、B站、12306、抖音、笔趣阁、漫画小说下载、音乐电影下载等
https://cuijiahua.com/blog/spider/
18.34k stars 5.96k forks source link

爬虫pycharm报错 #16

Closed zxy126 closed 6 years ago

zxy126 commented 6 years ago

你好,从CSDN上看到你的爬虫教程觉得很有趣点了个赞就跟着照做,但出现了点问题望能回复 问题很简单,在pharm中 import requests

if name == 'main': target = 'http://gitbook.cn/' req = requests.get(url=target) print(req.text)

会报错
D:\Python\Python36\python.exe "C:/Users/zxy/PycharmProjects/Python Excerise/WebSpider/random.py" Traceback (most recent call last): File "C:/Users/zxy/PycharmProjects/Python Excerise/WebSpider/random.py", line 1, in import requests File "D:\Python\Python36\lib\site-packages\requests__init__.py", line 97, in from . import utils File "D:\Python\Python36\lib\site-packages\requests\utils.py", line 11, in import cgi File "D:\Python\Python36\lib\cgi.py", line 44, in import tempfile File "D:\Python\Python36\lib\tempfile.py", line 45, in from random import Random as _Random ImportError: cannot import name 'Random'

但是copy到cmd的python中运行没出现问题

Jack-Cherish commented 6 years ago

@zxy126 你这是因为pycharm里没有配置后环境,编译器找不到你安装的requests包。

zxy126 commented 6 years ago

@Jack-Cherish 哈哈哈哈我下次再也不随便给文件起名为random了,后来发现是因为我文件名叫random,然后自然无法从里面导入。 无论如何谢谢你的回复与教程