IDE cannot install Csv/Config/Decouple import

Greetings, i started setting up base.py(settings.py) however when importing these lines

import dj_database_url

from decouple import Csv, config

from unipath import Path

I tried to install via the IDE(PYCharm), as recommended by the debugger itself, but I get errors.

Collecting decouple
  Using cached decouple-0.0.7.tar.gz (3.3 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'

ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\cli\req_command.py", line 245, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\commands\install.py", line 377, in run
    requirement_set = resolver.resolve(
                      ^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 95, in resolve
    result = self._result = resolver.resolve(
                            ^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 397, in resolve
    self._add_to_criteria(self.state.criteria, r, parent=None)
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 173, in _add_to_criteria
    if not criterion.candidates:
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\resolvelib\structs.py", line 156, in __bool__
    return bool(self._sequence)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 155, in __bool__
    return any(self)
           ^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 47, in _iter_built
    candidate = func()
                ^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 182, in _make_candidate_from_link
    base: Optional[BaseCandidate] = self._make_base_candidate_from_link(
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 228, in _make_base_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
                                       ^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 293, in __init__
    super().__init__(
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 156, in __init__
    self.dist = self._prepare()
                ^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 225, in _prepare
    dist = self._prepare_distribution()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 304, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\operations\prepare.py", line 525, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\operations\prepare.py", line 640, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\operations\prepare.py", line 71, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\distributions\sdist.py", line 54, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\distributions\sdist.py", line 124, in _install_build_reqs
    build_reqs = self._get_build_requires_wheel()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\distributions\sdist.py", line 101, in _get_build_requires_wheel
    return backend.get_requires_for_build_wheel()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_internal\utils\misc.py", line 751, in get_requires_for_build_wheel
    return super().get_requires_for_build_wheel(config_settings=cs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\pyproject_hooks\_impl.py", line 166, in get_requires_for_build_wheel
    return self._call_hook('get_requires_for_build_wheel', {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\pyproject_hooks\_impl.py", line 321, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last):
  File "C:\Users\OtterAndFinek\.virtualenvs\TattooFoundlerProject-1CIClaAs\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 77, in _build_backend
    obj = import_module(mod_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OtterAndFinek\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1304, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1318, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'setuptools'


[notice] A new release of pip is available: 23.3.2 -> 24.0
[notice] To update, run: python.exe -m pip install --upgrade pip

After several attempts, I decided to try to do the same in PowerShell as an admin. Everything was installed there, but in the IDE itself, even after a restart, this problem remains.

This is what is shown in the powershell console.


PS C:\Windows\system32> cd E:\TattooFoundlerProject\TattooFoundler PS E:\TattooFoundlerProject\TattooFoundler> pip install decouple Requirement already satisfied: decouple in c:\users\otterandfinek\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (0.0.7) PS E:\TattooFoundlerProject\TattooFoundler> pip install unipath Requirement already satisfied: unipath in c:\users\otterandfinek\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (1.1) PS E:\TattooFoundlerProject\TattooFoundler> pip install setuptools >> Requirement already satisfied: setuptools in c:\users\otterandfinek\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (68.0.0) PS E:\TattooFoundlerProject\TattooFoundler> pip cache purge >> Files removed: 246 PS E:\TattooFoundlerProject\TattooFoundler> pip install decouple Requirement already satisfied: decouple in c:\users\otterandfinek\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (0.0.7) PS E:\TattooFoundlerProject\TattooFoundler> pip install https://pypi.org/simple/decouple/0.5.0/decouple-0.5.0-py3-none-any.whl >> Collecting decouple==0.5.0   ERROR: HTTP error 404 while getting https://pypi.org/simple/decouple/0.5.0/decouple-0.5.0-py3-none-any.whl ERROR: Could not install requirement decouple==0.5.0 from https://pypi.org/simple/decouple/0.5.0/decouple-0.5.0-py3-none-any.whl because of HTTP error 404 Client Error: Not Found for url: https://pypi.org/simple/decouple/0.5.0/decouple-0.5.0-py3-none-any.whl for URL https://pypi.org/simple/decouple/0.5.0/decouple-0.5.0-py3-none-any.whl

As you can see, I tried to install them manually, cleared the cache and tried to reinstall, but this did not produce any results, what could be the problem?

I originally got stuck on this because of a runserver bug

this is my settings.py

import dj_database_url
from decouple import Csv, config
from unipath import Path



BASE_DIR = Path(__file__).resolve().parent.parent


# ==============================================================================
# CORE SETTINGS
# ==============================================================================

SECRET_KEY = config("SECRET_KEY", default="django-insecure$TattooFoundler.settings.local")

DEBUG = config("DEBUG", default=True, cast=bool)

ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="127.0.0.1,localhost", cast=Csv())


INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "TattooFoundler.apps.accounts",
    "TattooFoundler.apps.core",
]

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

ROOT_URLCONF = "TattooFoundler.urls"

INTERNAL_IPS = ["127.0.0.1"]

WSGI_APPLICATION = "TattooFoundler.wsgi.application"


# ==============================================================================
# MIDDLEWARE SETTINGS
# ==============================================================================

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]


# ==============================================================================
# TEMPLATES SETTINGS
# ==============================================================================

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / "templates"],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    },
]


# ==============================================================================
# DATABASES SETTINGS
# ==============================================================================

DATABASES = {
    "default": dj_database_url.config(
        default=config("DATABASE_URL", default="postgres://TattooFoundler:TattooFoundler@localhost:5432/TattooFoundler"),
        conn_max_age=600,
    )
}


# ==============================================================================
# AUTHENTICATION AND AUTHORIZATION SETTINGS
# ==============================================================================

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
    },
]


# ==============================================================================
# I18N AND L10N SETTINGS
# ==============================================================================

LANGUAGE_CODE = config("LANGUAGE_CODE", default="en-us")

TIME_ZONE = config("TIME_ZONE", default="UTC")

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = [BASE_DIR / "locale"]


# ==============================================================================
# STATIC FILES SETTINGS
# ==============================================================================

STATIC_URL = "/static/"

STATIC_ROOT = BASE_DIR.parent.parent / "static"

STATICFILES_DIRS = [BASE_DIR / "static"]

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)


# ==============================================================================
# MEDIA FILES SETTINGS
# ==============================================================================

MEDIA_URL = "/media/"

MEDIA_ROOT = BASE_DIR.parent.parent / "media"



# ==============================================================================
# THIRD-PARTY SETTINGS
# ==============================================================================

DEBUG = config('DEBUG', default=True, cast=bool)
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)

# ==============================================================================
# FIRST-PARTY SETTINGS
# ==============================================================================

TattooFoundler_ENVIRONMENT = config("TattooFoundler_ENVIRONMENT", default="local")

versions, which already means that I have them installed…

Decouple 0.0.7 - installed in the root of the project (although I personally didn’t find anything new there)
Setuptools 68.0.0 - similar.
CSV - I haven’t figured out how to install it at all, but this is not so important, because most likely it can be solved faster.
Config 0.5.1
Python - 3.7.9
Unipath 1.1
pathlib2 (aka path) - 2.3.7.post1.
I updated pip - it didn’t help. 24.0 now.

so this is how looks my requirements settings.txt
dj-database-url==0.5.0
Django==3.2.4
psycopg2-binary==2.9.1
python-decouple==3.4
pytz==2021.1
Config==0.5.1
Python==3.7.9
Unipath==1.1
pathlib2==2.3.7.post1
pip==24.0

Are you doing all of this in a virtual environment, or are you trying to do this with the “system-level” installation of Python? If the latter, you really want to use a virtual environment. See How to install Django on Windows | Django documentation | Django

It also looks like you may have conflicting modules here. You show that you may have both decouple and python-decouple installed. It appears that there is a naming conflict involved between the two. You need to remove decouple and reinstall python-decouple.

2 Likes

I’m doing this in a virtual environment, which in turn is located in the env folder in the project root, I tried installing decouple both globally (pip install ) and locally (cd *directory path * > pip install ), however I don’t I cleaned the installation cache after myself, for example, after the global one. However, I did not install them immediately and on different days, because I was busy, the problem is that the global one does not work separately.

The point is, you do not want the package “decouple”. You only want the package “python-decouple”. Do not install “decouple”, and if it is installed, remove it and then reinstall “python-decouple”.

There is a naming conflict between the two, and having both installed is going to cause problems.

2 Likes
PS E:\TattooFoundlerProject\venv> cd C:\
PS C:\> pip uninstall python-decouple
Found existing installation: python-decouple 3.8
Uninstalling python-decouple-3.8:
  Would remove:
    c:\users\otterandfinek\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages\decouple.py
    c:\users\otterandfinek\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages\python_decouple-3.8.dist-info\*
Proceed (Y/n)? y
  Successfully uninstalled python-decouple-3.8
PS C:\> pip uninstall decouple
WARNING: Skipping decouple as it is not installed.
PS C:\> pip uninstall python-decouple
WARNING: Skipping python-decouple as it is not installed.
PS C:\> cd E:\TattooFoundlerProject\venv
PS E:\TattooFoundlerProject\venv> pip uninstall decouple
WARNING: Skipping decouple as it is not installed.
PS E:\TattooFoundlerProject\venv> pip uninstall python-decouple
WARNING: Skipping python-decouple as it is not installed.
PS E:\TattooFoundlerProject\venv> pip install python-decouple
Collecting python-decouple
  Using cached python_decouple-3.8-py3-none-any.whl.metadata (14 kB)
Using cached python_decouple-3.8-py3-none-any.whl (9.9 kB)
Installing collected packages: python-decouple
Successfully installed python-decouple-3.8
PS E:\TattooFoundlerProject\venv>

It seems like I reinstalled it, but restarting the IDE did not give a good result)

Just changing to a venv directory does not activate it. You need to activate the virtual environment for it to be used. See the docs referenced above.

2 Likes

So, it seems to have worked, only for some reason in another IDE (VSC), but in PYCHARM there is still an error. But let’s skip this point.

Now he’s complaining about directions - (VSC IDE)

PS E:\TattooFoundlerProject> & e:/TattooFoundlerProject/venv/Scripts/python.exe e:/TattooFoundlerProject/TattooFoundler/TattooFoundler/settings/base.py
Traceback (most recent call last):
File “e:/TattooFoundlerProject/TattooFoundler/TattooFoundler/settings/base.py”, line 63, in
“DIRS”: [BASE_DIR / “templates”],
TypeError: unsupported operand type(s) for /: ‘Path’ and ‘str’
PS E:\TattooFoundlerProject>

The prompt here does not give any indication that the virtual environment is active.

Try running this directly from the command prompt. Let’s make sure you’ve got the environment set up correctly before worrying about integration with an IDE.

2 Likes
PS E:\TattooFoundlerProject\venv\Scripts> cd E:\TattooFoundlerProject
PS E:\TattooFoundlerProject> virtualenv -p python3 venv
>>
created virtual environment CPython3.7.9.final.0-64 in 17081ms
  creator Venv(dest=E:\TattooFoundlerProject\venv, clear=False, no_vcs_ignore=False, global=False, describe=CPython3Windows)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\OtterAndFinek\AppData\Local\pypa\virtualenv)
    added seed packages: pip==23.3.1, setuptools==68.0.0, wheel==0.42.0
  activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
PS E:\TattooFoundlerProject> venv\Scripts\activate
(venv) PS E:\TattooFoundlerProject> pip install -r requirements.txt

Isn’t the tag on the command line an indicator that the virtual environment is running?

Yes, but I did not see that tag in the output you showed at IDE cannot install Csv/Config/Decouple import - #7 by CharonIkh when you tried to run it in VSC.

1 Like

This error (if redirected correctly) was more-less fixed by adding the pathlib import.

import dj_database_url

from decouple import Csv, config

from unipath import Path

from pathlib import Path

After installing everything necessary in venv and running the debugger, it seems like I didn’t find any errors, if you count
PS E:\TattooFoundlerProject> & e:/TattooFoundlerProject/venv/Scripts/python.exe e:/TattooFoundlerProject/TattooFoundler/TattooFoundler/settings/base.py - like a successful launch.