1. 程式人生 > 程式設計 >使用PyCharm安裝pytest及requests的問題

使用PyCharm安裝pytest及requests的問題

電腦環境:windows7 64位 python3.7

問題:在PyCharm中,使用setting下的project Interpreter安裝pytest以及requests失敗

解決方法:(親測有效)

1、開啟Gitbash,定位到python的安裝目錄:我的安裝目錄是 D:\pythonAnZhuang\Python37\Scripts

使用PyCharm安裝pytest及requests的問題

2、輸入:pip install requests,等待安裝完成

使用PyCharm安裝pytest及requests的問題

3、輸入:pip install pytest,等待安裝完成

使用PyCharm安裝pytest及requests的問題

4、檢測是否安裝成功的方法:

第一種:pip list 可看到清單中有pytest以及requests

使用PyCharm安裝pytest及requests的問題

第二種:開啟python3.7的IDE,輸入 import pytest不報錯,輸入import requests不報錯

使用PyCharm安裝pytest及requests的問題

5、開啟PyCharm

可以在程式碼中使用pytest以及requests。如果不能匯入,檢查pytest和requests是否在虛擬環境中。

(我的其中一個包requests在虛擬環境中,轉移到虛擬環境中建立指令碼匯入requests成功。)

使用PyCharm安裝pytest及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內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!