pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

BUG: Unable to install pytensor as a package with pip install -e

Open tanish1729 opened this issue 1 year ago • 11 comments

Describe the issue:

I installed pytensor using pip install -e <path_to_my_fork> but i keep running into errors after that and cant even do simple imports. Everything seems to be failing because of image

Reproducable code example:

import pytensor
print(pytensor.__version__)

Error message:

AttributeError: module 'pytensor' has no attribute '__version__'

PyTensor version information:

Can't check version

Context for the issue:

No response

tanish1729 avatar Jul 19 '24 08:07 tanish1729

cc: @Armavica @maresb

jessegrabowski avatar Jul 19 '24 08:07 jessegrabowski

Hi @tanish1729, this is concerning, thanks so much for reporting it!

Let's try and diagnose this.

Please try running

import pytensor

print(pytensor.__file__)

This should report the location of __init__.py where __version__ is defined. I'd first ensure that the Python interpreter you're running is finding the expected copy of PyTensor.

The next thing I'd look at is if your version of __init__.py is up-to-date. (@Armavica made some changes last week, so perhaps the issue is that you need to pull in those changes.) The __version__ attribute is defined on this line. If that line executes, then I wouldn't expect the missing attribute you're seeing.

I hope it's something simple like this and not something more serious.

maresb avatar Jul 19 '24 10:07 maresb

image

is pytensor not installed or something? cuz it is showing me the location when i try to just see pytensor

tanish1729 avatar Jul 19 '24 10:07 tanish1729

Hi @tanish1729, thanks for the info!

I suspect that Python could be getting confused with a conflicting directory named pytensor.

What's your current directory and Python search path? You can find them with

from pathlib import Path
import sys

print(Path.cwd())
print(sys.path)

maresb avatar Jul 19 '24 12:07 maresb

image i already uninstalled pytensor and did `conda clean` and the new package always gets installed with the name its showing there

tanish1729 avatar Jul 19 '24 13:07 tanish1729

I have a theory on what's going wrong.

First I assume that your clone of PyTensor is in /Users/tanish/Desktop/idk/pymc-gsoc/pytensor.

If you are running VS Code / Jupyter from /Users/tanish/Desktop/idk/pymc-gsoc and import pytensor then it will see /Users/tanish/Desktop/idk/pymc-gsoc/pytensor as the Python project because the directory is named pytensor. Instead, it needs to find the directory /Users/tanish/Desktop/idk/pymc-gsoc/pytensor/pytensor (note pytensor twice at the end).

If you're in VS Code, then you should open the folder /Users/tanish/Desktop/idk/pymc-gsoc/pytensor instead of /Users/tanish/Desktop/idk/pymc-gsoc. Similarly, if you're running Jupyter, you should start it inside /Users/tanish/Desktop/idk/pymc-gsoc/pytensor.

I find this behavior from Python extremely frustrating.

I'm very tempted to suggest the following, but I'm not sure if this potentially introduces new issues:

Put the following contents into /Users/tanish/Desktop/idk/pymc-gsoc/pytensor/__init__.py and try what you were doing before.

from pathlib import Path

likely_repo_root = Path(__file__).parent

raise RuntimeError(
    f"Python is looking for PyTensor in {likely_repo_root}, but it's "
    f"actually located in {likely_repo_root / 'pytensor'}. Probably "
    f"you need to change your working directory from {Path.cwd()} "
    f"to {likely_repo_root}."
)

maresb avatar Jul 19 '24 13:07 maresb

CC @aseyboldt because we was also facing this issue yesterday

ricardoV94 avatar Jul 19 '24 13:07 ricardoV94

Turned this into a PR in #949

maresb avatar Jul 20 '24 09:07 maresb

hey @maresb, yes it did start working fine after i went into the pytensor directory containing all the files. however, this is kinda redundant for what i wanted to do. if im already inside the cloned directory and running all the imports, isnt that the same as using the package locally (i.e I should be able to do this without pip install as well). what i wanted to do was install the current version of my local pytensor on the system so it could run in other places too.

tanish1729 avatar Jul 20 '24 15:07 tanish1729

if im already inside the cloned directory and running all the imports, isnt that the same as using the package locally

Yes, but in this case you're clobbering the pip installed PyTensor with the valid PyTensor from your current directory.

As long as you've pip installed it, it should work anywhere else that doesn't have a conflicting pytensor subdirectory. Does this make sense?

maresb avatar Jul 20 '24 15:07 maresb

yes i tried that and it was working. i get what the problem is now. thanks!

tanish1729 avatar Jul 20 '24 16:07 tanish1729