I’m on Windows 10, using VisualStudio Code. (I’m a C# programmer). But I think I didn’t install the various elements correctly. Most examples run OK, but then:
In lesson 2 of the python package index the app’s first line is:
import requests
but this results in an error: Module not found.
What to do?
I ran python -m pip show requests
and it returned that I have version 2.26.0.
SO, why can’t I import requests?
And when I run pip3 list I get:
Package Version
certifi 2021.10.8
charset-normalizer 2.0.8
idna 3.3
pip 21.3.1
requests 2.26.0
setuptools 57.4.0
urllib3 1.26.7
wheel 0.37.0
BUT I think something else is amiss. In the lesson, after running env -m venv env, there is no bin folder created.
Thanks.
It’s probably a virtual env related issue.
- Check if you activated your virtualenv
- Check if the package is installed
- Check if the VSCode’s Python interpreter path is set to your virtualenv’s Python interpreter.
Also, just use pipenv for local development. It’s way more convenient.
Install pipenv and in your project root
mkdir .venv
pipenv shell
pipenv install requests
python your_app.py
Thank you. I’ll try this tomorrow and let you know.
How do I check to see if my virtualenv is activated? How do I determine if a particular package is installed? And where is my vscode python interpreter path?
Package Version
backports.entry-points-selectable 1.1.1
certifi 2021.10.8
charset-normalizer 2.0.8
distlib 0.3.3
filelock 3.4.0
idna 3.3
pip 21.3.1
pipenv 2021.11.23
platformdirs 2.4.0
requests 2.26.0
setuptools 57.4.0
six 1.16.0
urllib3 1.26.7
virtualenv 20.10.0
virtualenv-clone 0.5.7
wheel
BUT more important I have no idea about the Python setup. I mean, I’ve done 70% of the beginning lessons but unlike VS projects where most everything is easy to find in the folders, I’m confused about the python3 setup.
I’m unsure what you are talking about. What aspect of setup?
I set up the virtual env and using that I successfully downloaded and installed requests and ran it, no problem. So I made it all work (somehow).
Thanks to all for your suggestions and help!!!
RON
Cool, it’s easy mode from there. There are also other tools you can try pipenv, conda, poetry… They are all great.