電腦環境:windows7 64位 python3.7
問題:在PyCharm中,使用setting下的project Interpreter安裝pytest以及requests失敗
解決方法:(親測有效)
1、打開Gitbash,定位到python的安裝目錄:我的安裝目錄是 D:\pythonAnZhuang\Python37\Scripts
2、輸入:pip install requests,等待安裝完成
3、輸入:pip install pytest,等待安裝完成
4、檢測是否安裝成功的方法:
第一種:pip list 可看到清單中有pytest以及requests
第二種:打開python3.7的IDE,輸入 import pytest不報錯,輸入import requests不報錯
5、打開PyCharm
可以在代碼中使用pytest以及requests。如果不能導入,檢查pytest和requests是否在虛擬環境中。
(我的其中一個包requests在虛擬環境中,轉移到虛擬環境中創建腳本導入requests成功。)
6、注意事項:在requests安裝后出現的問題:雖然程序中可以導入模塊,但是程序執行時仍報錯,提示找不到模塊。
解決方法:此時打開gitbash,定位到python安裝目錄,我的是 D:\pythonAnZhuang\Python37,先卸載request(執行pip unstall requests),然后再安裝(執行pip install requests)。
安裝后,回到PyCharm,打開setting下的project Interpreter安裝requests成功。
總結
到此這篇關于使用PyCharm安裝pytest及requests的問題的文章就介紹到這了,更多相關PyCharm安裝pytest及requests內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/qq_35055695/article/details/107702761