labscript-suite / labscript-utils

Shared modules used by the 𝘭𝘢𝘣𝘴𝘤𝘳𝘪𝘱𝘵 𝘴𝘶𝘪𝘵𝘦. Includes a graphical exception handler, debug tools, configuration management, cross platform filepath conversions, unit conversions and custom GUI widgets.
http://labscriptsuite.org
Other
2 stars 47 forks source link

Can't Imort userlib #63

Closed zakv closed 4 years ago

zakv commented 4 years ago

Hi All,

I'm attempting to get labscript running on a new computer with an anaconda developer install on Windows. The installation runs fine but I'm not able to import userlib, even after running labscript-profile-create. Instead I get ModuleNotFoundError: No module named 'userlib'. This occurs even with the default values in the labconfig. I'm able to import pythonlib just fine though.

In an interactive session I checked sys.path and it included C:\Users\UserName\labscript-suite\userlib and C:\Users\UserName\labscript-suite\userlib\pythonlib. I tried editing sys.path to move each of those up one directory, so sys.path then contained C:\Users\UserName\labscript-suite and C:\Users\UserName\labscript-suite\userlib. After that I was able to import both userlib and pythonlib in that interactive session without error.

Maybe the parent directories of userlib and pythonlib should be added to path instead? https://github.com/labscript-suite/labscript-utils/blob/2c7deba0b5c091b44a877f1cfe058df9b7d612aa/labscript_profile/__init__.py#L44-L60

Somewhat related: https://github.com/labscript-suite/labscript-utils/issues/43

This seems like an issue that others would have run into before so there may be something different about my set up somehow. Maybe it's because this computer never had a mercurial install of labscript on it? I checked sys.path on one of our other computers which still has a mercurial labscript install on it, and it included the paths to all three of C:\Users\UserName\labscript-suite, C:\Users\UserName\labscript-suite\userlib and C:\Users\UserName\labscript-suite\userlib\pythonlib,

Cheers, Zak

chrisjbillington commented 4 years ago

Hi Zak,

Userlib itself isn't intended to be importable, rather its contents are. So for example a module foo as userlib/labscriptlib/foo.py is importable as import labscriptlib.foo

If you need a general-purpose dumping ground for Python modules, that's what pythonlib is intended for. A module bar as userlib/pythonlib/bar.py is importable as import bar.

(Since pythonlib is in userlib (perhaps a bad decision), bar may also be imported as import pythonlib.bar, but that's not advised)

As a side effect of the way the labscript suite installation used to work under mercurial, userlib was directly importable - this was because its parent directory (where the labscript suite modules were located) was added to the python path. That was not ideal (lots of random things in the labscript suite install directory were importable as a result), and is not the case anymore after the move to git and standard packaging techniques.

So I think this is working as intended! If you can confirm you're able to import your stuff given this explanation, then I'll close this issue. And let me know if I've misunderstood anything!

zakv commented 4 years ago

Ah I see, I've been writing all of my imports relative to userlib. I think I had somehow tripped the double import denier long ago and decided to always include userlib. in the import. Anyway just removing the leading userlib. from imports should be an easy fix, thanks for the help!