Python 导入requests报错No module named requests

原文链接:http://www.cnblogs.com/PeterZhang1520389703/p/8615885.html

刚开始是在Pycharm里面,发现就是不对,导入老提示No module named requests这个错误。
后面发现是指向的python.exe路径不对,到setting里面设置换一下路径就好。

 

 

转载于:https://www.cnblogs.com/PeterZhang1520389703/p/8615885.html

展开阅读全文
博主设置当前文章不允许评论。

python:no module named MySQLdb

03-05

想用django开发网站。使用的是python2.7,操作系统win10.已经安装好了Anaconda和mysql。现在想进行连接数据库,已经在网站下载并安装了多个版本的python-mysql驱动(1.2.3版本等),然后再import MySQLdb,还是提示no module named MySQLdbrnrnrn在C:\Anaconda2\Lib\site-packages也已经有了C:\Anaconda2\Lib\site-packages\MySQL_python-1.2.3-py2.7.egg-info和C:\Anaconda2\Lib\site-packages\MySQLdb。rnrn为什么就是不能成功呢?rnrndjango在启动服务的时候,错误为:rnC:\Anaconda2\Django-1.9.4\django\bin\hello>python manage.py runsever 0.0.0.0:8080rnTraceback (most recent call last):rn File "manage.py", line 10, in rn execute_from_command_line(sys.argv)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\core\management\__init__.py", line 353, in execute_from_command_linern utility.execute()rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\core\management\__init__.py", line 327, in executern django.setup()rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\__init__.py", line 18, in setuprn apps.populate(settings.INSTALLED_APPS)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\apps\registry.py", line 108, in populatern app_config.import_models(all_models)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\apps\config.py", line 202, in import_modelsrn self.models_module = import_module(models_module_name)rn File "F:\Anaconda\lib\importlib\__init__.py", line 37, in import_modulern __import__(name)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\contrib\auth\models.py", line 4, in rn from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManagerrn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\contrib\auth\base_user.py", line 49, in rn class AbstractBaseUser(models.Model):rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\models\base.py", line 108, in __new__rn new_class.add_to_class('_meta', Options(meta, app_label))rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\models\base.py", line 299, in add_to_classrn value.contribute_to_class(cls, name)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\models\options.py", line 263, in contribute_to_classrn self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\__init__.py", line 36, in __getattr__rn return getattr(connections[DEFAULT_DB_ALIAS], item)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\utils.py", line 212, in __getitem__rn backend = load_backend(db['ENGINE'])rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\utils.py", line 116, in load_backendrn return import_module('%s.base' % backend_name)rn File "F:\Anaconda\lib\importlib\__init__.py", line 37, in import_modulern __import__(name)rn File "F:\Anaconda\lib\site-packages\django-1.9.4-py2.7.egg\django\db\backends\mysql\base.py", line 28, in rn raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)rndjango.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb 论坛

python 报错 ,显示ModuleNotFoundError: No module named 'exception'

05-02

显示错误,使用的是python3.6rn如果不能够使用这个模块,可以换成什么呢? 还是python3没有整个模块呢rnrn[code=python]Traceback (most recent call last):rn File "C:\Users\IBM\Desktop\商品信息.py", line 4, in rn from exception import ValueErrorrnModuleNotFoundError: No module named 'exception'[/code]rnrn[code=python]from lxml import html rnimport csv,os,jsonrnimport requestsrnfrom exception import ValueErrorrnfrom time import sleeprnrndef AmzonParser(url):rn headers = 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'rn page = requests.get(url,headers=headers)rn while True:rn sleep(3)rn try:rn doc = html.fromstring(page.content)rn XPATH_NAME = '//h1[@id="title"]//text()'rn XPATH_SALE_PRICE = '//span[contains(@id,"ourprice") or contains(@id,"saleprice")]/text()'rn XPATH_ORIGINAL_PRICE = '//td[contains(text(),"List Price") or contains(text(),"M.R.P") or contains(text(),"Price")]/following-sibling::td/text()'rn XPATH_CATEGORY = '//a[@class="a-link-normal a-color-tertiary"]//text()'rn XPATH_AVAILABILITY = '//div[@id="availability"]//text()'rnrn RAW_NAME = doc.xpath(XPATH_NAME)rn RAW_SALE_PRICE = doc.xpath(XPATH_SALE_PRICE)rn RAW_CATEGORY = doc.xpath(XPATH_CATEGORY)rn RAW_ORIGINAL_PRICE = doc.xpath(XPATH_ORIGINAL_PRICE)rn RAw_AVAILABILITY = doc.xpath(XPATH_AVAILABILITY)rnrn NAME = ' '.join(''.join(RAW_NAME).split()) if RAW_NAME else Nonern SALE_PRICE = ' '.join(''.join(RAW_SALE_PRICE).split()).strip() if RAW_SALE_PRICE else Nonern CATEGORY = ' > '.join([i.strip() for i in RAW_CATEGORY]) if RAW_CATEGORY else Nonern ORIGINAL_PRICE = ''.join(RAW_ORIGINAL_PRICE).strip() if RAW_ORIGINAL_PRICE else Nonern AVAILABILITY = ''.join(RAw_AVAILABILITY).strip() if RAw_AVAILABILITY else Nonernrn if not ORIGINAL_PRICE:rn ORIGINAL_PRICE = SALE_PRICErnrn if page.status_code!=200:rn raise ValueError('captha')rn data = rn 'NAME':NAME,rn 'SALE_PRICE':SALE_PRICE,rn 'CATEGORY':CATEGORY,rn 'ORIGINAL_PRICE':ORIGINAL_PRICE,rn 'AVAILABILITY':AVAILABILITY,rn 'URL':url,rn rnrn return datarn except Exception as e:rn print (e) rndef ReadAsin():rn # AsinList = csv.DictReader(open(os.path.join(os.path.dirname(__file__),"Asinfeed.csv")))rn AsinList = ['B0046UR4F4',rn 'B00JGTVU5A',rn 'B00GJYCIVK',rn 'B00EPGK7CQ',rn 'B00EPGKA4G',rn 'B00YW5DLB4',rn 'B00KGD0628',rn 'B00O9A48N2',rn 'B00O9A4MEW',rn 'B00UZKG8QU',]rn extracted_data = []rn for i in AsinList:rn url = "http://www.amazon.com/dp/"+irn print ("Processing: "+url)rn extracted_data.append(AmzonParser(url))rn sleep(5)rn f=open('data.json','w')rn json.dump(extracted_data,f,indent=4)rnrnrnif __name__ == "__main__":rn ReadAsin()rn[/code] 论坛

没有更多推荐了,返回首页