0
Follow
0
View

The requests module was installed and the import reported an error

cyl821122 注册会员
2023-02-27 22:28

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > the problem is likely due to the Python interpreter in PyCharm with you on the command line run the Python interpreter is different, The module cannot be imported. You can check in PyCharm to see if the Python interpreter you used is correct. The operations are as follows:

  1. Open PyCharm.
  2. Click on "File" in the menu bar, then select "Settings".
  3. In the window that appears, expand "Project" and select "Project Interpreter".
  4. In the right pane, view the Python interpreter used by the current project. If it is not the interpreter you use on the command line, select the correct interpreter.

If your interpreter is correct and the requests module still cannot be imported, try installing the requests using pip in PyCharm:

  1. Open PyCharm.
  2. Click on "File" in the menu bar, then select "Settings".
  3. In the window that appears, expand "Project" and select "Project Interpreter".
  4. In the right pane, click the plus button in the top left corner.
  5. In the window that pops up, search for requests and click "Install Package".
  6. Wait for the installation to complete and try importing the requests module.
If none of the above works, try reinstalling the requests module on the command line, making sure PyCharm is the same Python interpreter used on the command line:
  1. Open the command line.
  2. Enter the command "pip uninstall requests" to uninstall the installed requests module.
  3. Reinstall the requests module by entering the command "pip install requests".
  4. Attempts to import the requests module in PyCharm.
dian19920226 注册会员
2023-02-27 22:28
cyf198711091 注册会员
2023-02-27 22:28

This answer references GPT, GPT_Pro to better solve the problem.
Pycharm is a python development tool designed to simplify python development. Improve development efficiency. You installed the requests module in pycharm, and the pip list shows that the installation was successful, but No module named requests' is reported as soon as you import it. This is due to a discrepancy between the version of python used by PyCharm and the version of python in which you installed the requests module.

To solve this problem, you first need to confirm the version of python used by pycharm, open pycharm, and select File-Settings-Project from the menu bar: - Project Interpreter, where you can see the current version of Python used by pycharm, if it's not the version you want, you can select Project Interpreter - Add Local and install or find the Python version you want. Reinstall the requests module.

# 示例代码
import requests 
response = requests.get('https://www.example.com') 
print(response.status_code)

If the answer is helpful, please accept it.