Problem with setuptools when running code?

Dear Python experts,

When I run my code in some machines I get the error pasted below. This does not seem to be happening in all the machines. It looks like a problem in the installation I am using setup tools for that. Does anyone have any idea what might be happening? I have reinstalled all my code in a new virtual environment but I keep seeing this.

Cheers.

stty: standard input: Inappropriate ioctl for device
/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/bin/apply_selection:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  __import__('pkg_resources').require('rx-tools==0.2.5')
Traceback (most recent call last):
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2765, in _dep_map
    return self.__dep_map
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2877, in __getattr__
    raise AttributeError(attr)
AttributeError: _Distribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 35, in __init__
    parsed = _parse_requirement(requirement_string)
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 73, in _parse_requirement
    name_token = tokenizer.expect(
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/_tokenizer.py", line 140, in expect
    raise self.raise_syntax_error(f"Expected {expected}")
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/_tokenizer.py", line 165, in raise_syntax_error
    raise ParserSyntaxError(
pkg_resources.extern.packaging._tokenizer.ParserSyntaxError: Expected package name at the start of dependency specifier

    ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/bin/apply_selection", line 4, in <module>
    __import__('pkg_resources').require('rx-tools==0.2.5')
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3304, in <module>
    def _initialize_master_working_set():
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3278, in _call_aside
    f(*args, **kwargs)
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3316, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 615, in _build_master
    ws.require(__requires__)
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 952, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 818, in resolve
    new_requirements = dist.requires(req.extras)[::-1]
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2800, in requires
    dm = self._dep_map
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2767, in _dep_map
    self.__dep_map = self._filter_extras(self._build_dep_map())
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2795, in _build_dep_map
    dm.setdefault(extra, []).extend(parse_requirements(reqs))
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/__init__.py", line 3149, in __init__
    super().__init__(requirement_string)
  File "/publicfs/ucas/user/campoverde/Packages/mambaforge/envs/rk/lib/python3.9/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 37, in __init__
    raise InvalidRequirement(str(e)) from e
pkg_resources.extern.packaging.requirements.InvalidRequirement: Expected package name at the start of dependency specifier


We would need to see exactly what you’re trying to do, as well (i.e., the command being run, and an explanation of the environment where it’s running. It looks like this is for a Python 3.9 installation on Linux, correct? And it’s being installed for a virtual environment? It looks like this is part of a larger automated process… ?)

1 Like

Dear Karl,

Thanks for your reply.

  1. The command is complicated, but I am doing a dry run which does only:
utility -h

and gets you the help setup menu setup using argparse. So it basically does nothing but importing a few modules and calling the argument parser.

  1. I am running in centOS 7, a computing cluster. The filesystem is shared and all the machines should have access to the same conda virtual environment.

  2. Yes, I am using python 3.9, with mamba, the environment was made with:

mamba create -n rk root=6.28 python=3.9
  1. The script is going to run many things, but the problem seems to happen at the very beginning, before anything happens, when only argparse has been involved.

Let me know if you need any other piece of information. However it does look like some sort of problem in the setup.py script that I use to install one of the projects in the environment. All the projects are been installed as editable, i.e. as pip install -e .

Cheers

Dear Experts,

I think I found the way out (strange, I ask for help for a problem I have had for days and immediately I seem to find the way out :slight_smile: ). In any case, it seems that when these projects are installed in editable mode I have to remove some egg stuff with:

purge()
{
    if [[ $PURGE -eq 0 ]];then
	return
    else
       for EGG_DIR in `find $PWD -name "*.egg-info*" -type d`;do
           echo "Removing $EGG_DIR"
	   rm -rf $EGG_DIR
       done
    fi
}

I tried reinstalling after removing those directories and sent these processes to 40 machines and no error appears anymore.

Cheers.