Technologicat / pyan

Static call graph generator. The official Python 3 version. Development repo.
GNU General Public License v2.0
324 stars 57 forks source link

pip install from pypi is broken for venvs #16

Closed ttylec closed 3 years ago

ttylec commented 5 years ago

Here is what I got when installed in fresh temporary python venv:

➜  ~ mktmpenv --python=/usr/bin/python3
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/ttylec/.virtualenvs/tmp-195183325368ab1e/bin/python3
Also creating executable in /home/ttylec/.virtualenvs/tmp-195183325368ab1e/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
This is a temporary environment. It will be deleted when you run 'deactivate'.
(tmp-195183325368ab1e) ➜  tmp-195183325368ab1e python --version
Python 3.6.8
(tmp-195183325368ab1e) ➜  tmp-195183325368ab1e pip install pyan3
Collecting pyan3
  Using cached https://files.pythonhosted.org/packages/1a/82/d1b47fbcde2472d5954b4ed70cc3acf67d27bb0e83cf9b5cd5785684c629/pyan3-1.0.4-py3-none-any.whl
Installing collected packages: pyan3
Successfully installed pyan3-1.0.4
(tmp-195183325368ab1e) ➜  tmp-195183325368ab1e pyan3
Traceback (most recent call last):
  File "/home/ttylec/.virtualenvs/tmp-195183325368ab1e/bin/pyan3", line 7, in <module>
    from pyan import main
ModuleNotFoundError: No module named 'pyan'

Installing from within cloned repo works.

Technologicat commented 5 years ago

I have to admit that, although it's not recommended, I usually use the system Python (with pip install --user for packages), so I hadn't noticed this. Thanks for letting me know!

Judging by the error message, it seems the pyan module is not getting installed to site-packages of the temporary venv for some reason. I take it installing other packages in a temporary venv works?

ttylec commented 5 years ago

Yes, it works. Just a bit more details:

when pip installed from git repo within temporary virtualenv

(tmp-1aed8d19cf30cb7d) ➜  pyan git:(master) ✗ head $(which pyan3)
#!/home/ttylec/.virtualenvs/tmp-1aed8d19cf30cb7d/bin/python3
# -*- coding: utf-8 -*-

import re
import sys

and when pip installed from pypi:

(tmp-5cd86f124b295af1) ➜  tmp-5cd86f124b295af1 head $(which pyan3)
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import re
import sys

In the latter case, the python interpreter path if not set properly (it points to system interpreter, not one within venv).

Technologicat commented 5 years ago

Thanks the analysis! The script using the wrong interpreter explains why it's not finding the module. Wait, I thought I already fix... aaaah, no, I didn't! See #11.

The hardcoded hashbang is at least part of it - there may also be something else. I suppose I'll first fix #11, and then set up a venv and have a look myself. :)

Technologicat commented 3 years ago

PyPI package pyan3 updated. Please try again with the latest version, and reopen this issue if necessary.

(This should work in the new 1.1.1.)