Open ataylor32 opened 6 months ago
pkg_resources
is used to read the current package version.
We should probably write the version into a file at build time instead with something like:
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
[tool.setuptools_scm]
write_to = "user_sessions/version.py"
version_scheme = "no-guess-dev"
init.py
can then use:
from . import version
__version__ = version.version
The error you're encountering, ModuleNotFoundError: No module named 'pkg_resources'
, typically occurs when the setuptools
package is not installed or is not properly configured in your Python environment. Here are some steps to resolve this issue:
Install or Upgrade setuptools
:
Ensure that setuptools
is installed and up-to-date. You can do this by running the following commands:
pip install --upgrade setuptools
Uninstall and Reinstall setuptools
:
If the above step doesn't work, try uninstalling and then reinstalling setuptools
:
pip uninstall -y setuptools
pip install setuptools
Upgrade pip
, setuptools
, and wheel
:
Sometimes, upgrading pip
, setuptools
, and wheel
can resolve the issue:
# For Unix/macOS
python3 -m pip install --upgrade pip setuptools wheel
# For Windows
py -m pip install --upgrade pip setuptools wheel
Create a Virtual Environment: If the issue persists, try creating a new virtual environment and installing the necessary packages within it:
# For Unix/macOS
python3 -m venv my_env
source my_env/bin/activate
# For Windows
py -m venv my_env
my_env\Scripts\activate
# Then install the required packages
pip install django django-user-sessions
setuptools_scm
If you need to write the version into a file at build time, you can configure setuptools_scm
as follows:
Add setuptools_scm
to your pyproject.toml
:
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
[tool.setuptools_scm]
write_to = "user_sessions/version.py"
version_scheme = "no-guess-dev"
Modify __init__.py
:
In your __init__.py
, use the following code to import the version:
from . import version
__version__ = version.version
By following these steps, you should be able to resolve the ModuleNotFoundError: No module named 'pkg_resources'
and run python manage.py shell
without any errors.
Expected Behavior
I should be able to run a command like
python manage.py shell
without any errors.Current Behavior
Your Environment
Relevant: https://github.com/python/cpython/issues/95299