[chimerax-users] Trouble with imports in ChimeraX bundle

Eric Pettersen pett at cgl.ucsf.edu
Tue Apr 5 09:51:56 PDT 2022


Hi William,
	I would recommend continuing to use relative imports.  Assuming you have a folder named 'X' that has a file named 'Y' with a class named 'Z' in it, you would import Z with:

	from .X.Y import Z

Two caveats are:

	(1) Y must have a file names __init__.py in it
	(2) You might need to import Y first, i.e.:

			import .X.Y
			from .X.Y import Z

--Eric

	Eric Pettersen
	UCSF Computer Graphics Lab


> On Apr 5, 2022, at 7:33 AM, William Hofsøy via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
> 
> Hi, I have been doing some restructuring and refactoring of my project and started having trouble with my imports and modules not being found. previously all my imports were relative for instance: "from . import tool"
> However this is a bit impractical now that I have a folder structure, so I have been trying to use absolute imports like from "src.toolname.pythonfile import class" but it seems my folder structure differs from how it is after installing it into ChimeraX. I am using pycharm as my editor and the automatic import paths they set up also fails, meanwhile i looked at the sys.path and there the structure is chimerax/packagename where packagename contains the files contained in my src.
> 
> So I was wondering if there is a way to set this up properly?
> _______________________________________________
> ChimeraX-users mailing list
> ChimeraX-users at cgl.ucsf.edu
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20220405/29dff5ab/attachment.html>


More information about the ChimeraX-users mailing list