Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'pkg_resources' when importing pandas_ta

I am quite a newbie when it comes to Python. I am trying to run someone else's code that contains references to pandas_ta. When I run the code I get the following errors:

File "/data/stuart/Projects/Python/BackTesting/Test/Test1.py", line 6, in <module>
import pandas_ta as ta
File "/data/stuart/Projects/Python/Env/lib/python3.12/site-packages/pandas_ta/__init__.py", line 7, in <module>
    from pkg_resources import get_distribution, DistributionNotFound
ModuleNotFoundError: No module named 'pkg_resources'

I am running Python 3.10.12 on Ubuntu 22.04 using PyCharm IDE Community version.

As I am a newbie I am somewhat reluctant to try many of the 'answers' I have found on this site until I have an idea as to the likely cause, and best solution. I don't want to make matters worse. What I have tried is the following:

sudo apt-get install --reinstall python-pkg-resources

Unfortunately the problem persists. Unfortunately, I want to use pandas_ta in some other projects as I was unable to get TA-Lib installed correctly. Any guidance or assistance would be much appreciated.

Regards, StuartM

like image 671
StuartM Avatar asked Nov 14 '25 11:11

StuartM


1 Answers

The error indicates that the pkg_resources module, part of the setuptools library, is not available in your Python environment. This module is used by pandas_ta for some of its operations.

Fixing the Issue

To resolve this, ensure that setuptools is installed in your Python environment. You can do this as follows:

  1. Install setuptools: Run the following command in your terminal:

    pip install setuptools
    
  2. Verify Installation: After installation, confirm that pkg_resources is available:

    python -c "import pkg_resources; print('pkg_resources is available')"
    

If the Issue Persists

If the error still occurs:

  • Upgrade pip and setuptools:
    pip install --upgrade pip setuptools
    
like image 108
Gregory Kovalchuk Avatar answered Nov 17 '25 10:11

Gregory Kovalchuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!