ModuleNotFoundError: No module named 'prettytable'

1.1k Views Asked by At

I have installed the package prettytable and I'm getting the message saying Requirement already satisfied: prettytable <>

Still I am getting the the error

ModuleNotFoundError: No module named 'prettytable'

Did I made a mistake here?

Any suggestions?

I have installed the package 'prettytable' with the command pip install prettytable and tried to to use the PrettyTable class.

I should not get any error right? But I'm getting that error.

1

There are 1 best solutions below

0
Bowman Zhu-MSFT On

I can reproduce your issue:

enter image description here

If your project is python application, then please make sure the package has been installed to this place:

enter image description here

enter image description here

enter image description here

I notice you have a tag named 'nuget-package' of your question, but in your situation, there is no relationship with nuget package. Python package is another thing.

When you encounter this issue, you need to make sure the package has been installed to target environment. 99.99% situation is the package is not in the correct place.

The situation maybe caused by multiple python versions, virtual environment, etc.

My local environment is very pure, only version python11, and no virtual environment. So when I use pip to successfully install the package prettytable, I can run the python script immediately.

enter image description here

Troubleshooting steps:

  1. Research where the package be installed:

If you have multiple Python environments or if you installed prettytable in a virtual environment, make sure that you have activated the correct environment where prettytable is installed when you run your script.

  1. Check Python Version:

Check the Python version you're using to run the script and the Python version you used to install prettytable. They should be the same. You can check the Python version by running python --version in your command line.

  1. Confirm whether the package has been really installed:

Confirm that prettytable was installed successfully by running the following command:

 pip show prettytable
 

This will give you information about the prettytable installation including the version and the location where it is installed:

enter image description here

  1. Check sys.path:

In your script, you can print out the Python path to see the directories where Python is looking for modules:

 import sys
 print(sys.path)
 

Make sure the directory where prettytable is installed is listed in the output.

  1. Reinstall prettytable:

Sometimes, reinstalling the package can help resolve installation issues. You can do this with the following commands:

 pip uninstall prettytable
 pip install prettytable
 

Anyway, if you provide more information of this issue, we could give more detailed suggestions/solution. The above steps are the common troubleshooting steps.