Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdm run don't exclude all site-packages in PYTHONPATH #828

Closed
1 task done
dev590t opened this issue Dec 31, 2021 · 8 comments
Closed
1 task done

pdm run don't exclude all site-packages in PYTHONPATH #828

dev590t opened this issue Dec 31, 2021 · 8 comments
Labels
🐛 bug Something isn't working

Comments

@dev590t
Copy link
Contributor

dev590t commented Dec 31, 2021

  • I have searched the issue tracker and believe that this is not a duplicate.

Steps to reproduce

pdm init
pdm run python3 -c "import sys; print(sys.path)"

Actual behavior

(base) echo $PYTHONPATH
/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582:/home/dev_1/.local/lib/python3.8/site-packages:/home/dev_1/.guix-profile/lib/python3.8/site-packages
(base) pdm run python3 -c "import sys; print(sys.path)"
['', '/home/dev_1/.guix-profile/lib/python3.8/site-packages', '/gnu/store/abznl1yzi6isa57mh1mj3fsdylksqd7m-python-3.8.2/lib/python38.zip', '/gnu/store/abznl1yzi6isa57mh1mj3fsdylksqd7m-python-3.8.2/lib/python3.8', '/gnu/store/abznl1yzi6isa57mh1mj3fsdylksqd7m-python-3.8.2/lib/python3.8/lib-dynload', '/tmp/pdm/__pypackages__/3.8/lib']

/home/dev_1/.guix-profile/lib/python3.8/site-packages is still in sys.path. My project load the system numpy instead of my pypackages numpy.

Environment Information

# Paste the output of `pdm info && pdm info --env` below:
(base) pdm info && pdm info --env
PDM version:        1.12.2
Python Interpreter: /home/dev_1/.guix-profile/bin/python3 (3.8)
Project Root:       /tmp/pdm
Project Packages:   /tmp/pdm/__pypackages__/3.8
{
  "implementation_name": "cpython",
  "implementation_version": "3.8.2",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.9.3-gnu",
  "platform_system": "Linux",
  "platform_version": "#1 SMP 1",
  "python_full_version": "3.8.2",
  "platform_python_implementation": "CPython",
  "python_version": "3.8",
  "sys_platform": "linux"
}

additional information

I have try to remove /home/dev_1/.guix-profile/lib/python3.8/site-packages from PYTHONPATH, but it seems pdm depend it to run.
I have try to search a configuration in pdm to explicit exclude this path, but not found.
related issue #100

@dev590t dev590t added the 🐛 bug Something isn't working label Dec 31, 2021
@frostming
Copy link
Collaborator

You shouldn't include any site-packages in PYTHONPATH, they are loaded every time, even if you are using incompatible Python versions.

I don't know why you say PDM depends on that, it shouldn't.

@dev590t
Copy link
Contributor Author

dev590t commented Dec 31, 2021

You shouldn't include any site-packages in PYTHONPATH, they are loaded every time, even if you are using incompatible Python versions.
I don't know why you say PDM depends on that, it shouldn't.

You can see if I remove some site-packages from my PYTHONPATH, pdm will not run

(base) echo $PYTHONPATH 
/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582:/home/dev_1/.local/lib/python3.8/site-packages:/home/dev_1/.guix-profile/lib/python3.8/site-packages
(base) pdm -V
Python Development Master (PDM), version 1.12.2
(base) export PYTHONPATH=/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582
(base) pdm -V
Traceback (most recent call last):
  File "/home/dev_1/.local/bin/pdm", line 5, in <module>
    from pdm.core import main
  File "/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/__init__.py", line 5, in <module>
    from pdm.cli.commands.base import BaseCommand
  File "/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/cli/commands/base.py", line 5, in <module>
    from pdm.cli.options import Option, global_option, project_option, verbose_option
  File "/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/cli/options.py", line 7, in <module>
    from click import secho
ModuleNotFoundError: No module named 'click'

In a new shell

(base) python3 -c "import click;print(click.__path__)"
['/home/dev_1/.local/lib/python3.8/site-packages/click']

I have installed pdm with

curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -

@frostming
Copy link
Collaborator

Make sure PYTHONPATH is /home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582 and run

/home/dev_1/.local/share/pdm/venv/bin/python -m pip list

To show whether click is installed

@dev590t
Copy link
Contributor Author

dev590t commented Dec 31, 2021

(base) export PYTHONPATH=/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582
(base) /home/dev_1/.local/share/pdm/venv/bin/python -m pip list
Package    Version
---------- -------
pdm        1.12.2
pip        21.3.1
setuptools 41.2.0

I have installed pdm following recommended-installation-method. Why the script haven't installed the dependancies of pdm into pdm 's site-packages?

@frostming
Copy link
Collaborator

Run /home/dev_1/.local/share/pdm/venv/bin/python -m pip install -I --force-reinstall pdm to see what it outputs, it may give some hints why it thinks the dependencies don't need to be installed.

@dev590t
Copy link
Contributor Author

dev590t commented Dec 31, 2021

Thanks! That runs. I remove pdm, and reinstalled it with

curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -

And this time, it is installed correctly

(base) /home/dev_1/.local/share/pdm/venv/bin/python -m pip list
Package         Version
--------------- -------
attrs           21.4.0
blinker         1.4
cached-property 1.5.2
click           8.0.3
..

I have try to reinstall it few times before, I don't why, but this time it is correctly installed

@dev590t dev590t closed this as completed Dec 31, 2021
@dev590t
Copy link
Contributor Author

dev590t commented Dec 31, 2021

Additional information, I have replace in .bashrc

if [ -n "$PYTHONPATH" ]; then
    export PYTHONPATH='/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582':$PYTHONPATH
else
    export PYTHONPATH='/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582'
fi

by

export PYTHONPATH='/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582'

to remove all site-packages.

I think the documentation should precise "don't include any site-packages in PYTHONPATH". Because this line export PYTHONPATH='/home/dev_1/.local/share/pdm/venv/lib/python3.8/site-packages/pdm/pep582':$PYTHONPATH from pdm --pep582 will include it. I can make a PR for that.

@frostming
Copy link
Collaborator

Good, go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants