pdm-project / pdm-venv

A plugin for pdm that enables virtualenv management
https://pdm-project.github.io/pdm-venv
MIT License
24 stars 4 forks source link

No module named 'editables' #26

Closed CharString closed 2 years ago

CharString commented 2 years ago

Many commands raise ModuleNotFoundError: No module named 'editables' after installing the project with pdm install

To Reproduce I have setup a repo to illustrate:

git clone git@github.com:CharString/issue649.git
cd issue649
pdm venv create
pdm install
pdm run python foo.py

It's named after pdm-project/pdm#649, but that one was solved, because using pep582 works fine.

Expected behavior I expect the same behaviour as without the plugin. When I remove the venv and use pep582 it works:

pdm venv remove
pdm use
pdm install
pdm run python foo.py

Screenshots

$ git clone git@github.com:CharString/issue649.git
Cloning into 'issue649'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (7/7), done.
remote: Total 7 (delta 0), reused 7 (delta 0), pack-reused 0
$ cd issue649/
$ pdm install
⠙ Resolving packages from lockfile...
⠋ Resolving packages from lockfile...
created virtual environment CPython3.9.5.final.0-64 in 109ms
  creator CPython3Posix(dest=/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/export/scratch1/home/ccw/.local/share/virtualenv)
    added seed packages: pip==21.3.1, setuptools==58.5.3, wheel==0.37.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,Power⠙ Resolving packages from lockfile...
Virtualenv /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue6All packages are synced to date, nothing to do.

Installing the project as an editable package...
  ✔ Install issue649 0.0-alpha successful

🎉 All complete!
$ pdm run python foo.py 
Error processing line 1 of /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/issue649.pth:

  Traceback (most recent call last):
    File "/usr/lib64/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/_issue649.py", line 1, in <module>
      from editables.redirector import RedirectingFinder as F
  ModuleNotFoundError: No module named 'editables'

Remainder of file ignored
Error processing line 1 of /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/issue649.pth:

  Traceback (most recent call last):
    File "/usr/lib64/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/_issue649.py", line 1, in <module>
      from editables.redirector import RedirectingFinder as F
  ModuleNotFoundError: No module named 'editables'

Remainder of file ignored
Error processing line 1 of /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/issue649.pth:

  Traceback (most recent call last):
    File "/usr/lib64/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/_issue649.py", line 1, in <module>
      from editables.redirector import RedirectingFinder as F
  ModuleNotFoundError: No module named 'editables'

Remainder of file ignored
Error processing line 1 of /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/issue649.pth:

  Traceback (most recent call last):
    File "/usr/lib64/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/_issue649.py", line 1, in <module>
      from editables.redirector import RedirectingFinder as F
  ModuleNotFoundError: No module named 'editables'

Remainder of file ignored
Error processing line 1 of /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/issue649.pth:

  Traceback (most recent call last):
    File "/usr/lib64/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/_issue649.py", line 1, in <module>
      from editables.redirector import RedirectingFinder as F
  ModuleNotFoundError: No module named 'editables'

Remainder of file ignored
Error processing line 1 of /export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/issue649.pth:

  Traceback (most recent call last):
    File "/usr/lib64/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/export/scratch1/home/ccw/.local/share/virtualenvwrapper/envs/issue649-v-dGyFzm-3.9/lib64/python3.9/site-packages/_issue649.py", line 1, in <module>
      from editables.redirector import RedirectingFinder as F
  ModuleNotFoundError: No module named 'editables'

Remainder of file ignored

System (please complete the following information):

$ cat /etc/system-release
Fedora release 32 (Thirty Two)
$ pipx runpip pdm freeze
appdirs==1.4.4
atoml==1.1.0
attrs==21.2.0
backports.entry-points-selectable==1.1.0
cached-property==1.5.2
click==8.0.3
distlib==0.3.3
editables==0.2
filelock==3.3.2
installer==0.3.0
packaging==21.2
pdm==1.11.1
pdm-pep517==0.9.2
pdm-venv==0.3.1
pep517==0.12.0
platformdirs==2.4.0
pyparsing==2.4.7
python-dotenv==0.19.1
pythonfinder==1.2.8
resolvelib==0.8.1
shellingham==1.4.0
six==1.16.0
tomli==1.2.2
virtualenv==20.10.0
CharString commented 2 years ago

The behaviour is very erratic. Sometimes it is fixed by installing editables by hand

$ pdm run pip install editables
...
Successfully installed editables-0.2
$ pdm run python foo.py
$ # no error

And then I can even uninstall

$ pdm run pip uninstall editables
Found existing installation: editables 0.2
...
  Successfully uninstalled editables-0.2
$ pdm run python foo.py 
$ # foo keeps working. No error, even though the module isn't there anymore:
$ pdm run python -c 'import editables'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'editables'

I have no idea where the editables package should be. As this adding editables to the virtualenv doesn't always work. I tried adding it to my project dependencies with pdm add editables, and then it is installed in the venv, but it still raises the Error when I try to run stuff in the project.

CharString commented 2 years ago

So apparently my editable installed packages end up in the site-packages under lib64, but editables is in the site-packages under lib. When I symlink to it under lib64 the errors disappear. I have no idea what to make of this. Or what the situation ought to look like.

frostming commented 2 years ago

Thanks for reporting, it is a bug with PDM project and has been fixed in the main branch. Plan to release the fix in about 3 days

CharString commented 2 years ago

@frostming I've just tested with version 1.11.2 in one of my projects, and when I re-run lock it does add ")editables" to the dependencies of my editable dependencies. But sync or install still install 'editables' under .lib in the venv, not under ./lib64. Creating a symlink under lib64 helps.

Is this a bug in editables? Or are we creating the .pth files incorrecly?

frostming commented 2 years ago

lib64 is for platform libraries(those with C-extensions), and lib is for pure python libraries, editables belong to the latter.