使用pipenv搭配IDLE或PyCharm时出现Traceback错误求助
Hey there! That Traceback error you're seeing in IDLE/PyCharm is almost certainly because those tools aren't using the virtual environment you created with pipenv—so they can't find the requests library you installed there. Let's fix this step by step for each tool:
Fixing IDLE's Environment Configuration
- First, grab the path to your pipenv virtual environment's Python interpreter. From your terminal output, this is:
(Pro tip: You can also run/Users/myname/.local/share/virtualenvs/spacy-JBK2xTM0/bin/pythonpipenv --pyin your project directory to get this path directly, no need to copy-paste from old logs!) - Open IDLE, then go to the top menu:
Options→Configure IDLE - Switch to the
Generaltab, look for thePython interpretersection, and click theBrowsebutton - Navigate to the interpreter path we found earlier, select it, and save the configuration
- Restart IDLE, and try importing requests again—this should work now!
Fixing PyCharm's Environment Configuration
- Open your project in PyCharm, then go to the top menu:
File→Settings(orPyCharm→Settingsif you're on a Mac) - In the settings window, expand
Project: [Your Project Name]and selectPython Interpreter - Click the gear icon in the top-right corner, then choose
Add - In the new window, select
Existing environment, then click the folder icon to browse for the virtual environment's Python interpreter (use the same path as above) - Select the interpreter, click
OK, then hitApplyandOKto save the settings - Wait for PyCharm to sync the environment dependencies, and your requests import should no longer throw errors!
内容的提问来源于stack exchange,提问作者RobH
相关产品推荐
相关产品推荐

