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

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

Open
tanish1729 opened this issue Jul 19, 2024 · 11 comments · May be fixed by #949
Open

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

tanish1729 opened this issue Jul 19, 2024 · 11 comments · May be fixed by #949
Labels
bug Something isn't working

Comments

@tanish1729
Copy link
Contributor

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 tanish1729 added the bug Something isn't working label Jul 19, 2024
@jessegrabowski
Copy link
Member

cc: @Armavica @maresb

@maresb
Copy link
Contributor

maresb commented Jul 19, 2024

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.

@tanish1729
Copy link
Contributor Author

image

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

@maresb
Copy link
Contributor

maresb commented Jul 19, 2024

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)

@tanish1729
Copy link
Contributor Author

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

@maresb
Copy link
Contributor

maresb commented Jul 19, 2024

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}."
)

@ricardoV94
Copy link
Member

CC @aseyboldt because we was also facing this issue yesterday

@maresb maresb linked a pull request Jul 20, 2024 that will close this issue
10 tasks
@maresb
Copy link
Contributor

maresb commented Jul 20, 2024

Turned this into a PR in #949

@tanish1729
Copy link
Contributor Author

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.

@maresb
Copy link
Contributor

maresb commented Jul 20, 2024

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?

@tanish1729
Copy link
Contributor Author

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

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

Successfully merging a pull request may close this issue.

4 participants