Unable to import pygal in Python despite installing it

47 Views Asked by At

I have successfully installed pygal but I am not able to import it in Python. Can you please settle this issue? Has it anything to do with virtual environment? How do I install pygal in virtual environment.

1

There are 1 best solutions below

4
pts On

Maybe there are multiple Python versions installed or multiple virtual environments on your system, and you have installed the package to the wrong one.

Use the same python command to install and run (without the leading $):

$ python -m pip install pygal
...
$ echo "import pygal; echo OK" >myprog.py
$ python myprog.py
OK

If you use IDLE, then start it like this:

$ python -c "from idlelib.pyshell import main; main()"

(It's too late to change the Python version or the virtual environment after IDLE has been started. It's too late to select the Python version or the virtual environment after pip install has been started. You have to do it first, and then only run the python command.)

It's important that you start everything with the (same) python command (rather than pip, idle etc.), and from the same virtual environment (venv), if any. That's the way you can make sure that you will be using the same Python version and modules.