[PY2] Import module fail

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

[PY2] Import module fail

#1

Post by miaz3 » Thu Sep 20, 2018 11:10 am

Hello guys,

I tried to call a module from another python script, and it fail.
  1. from test_ui import Ui_testForm
  2. ImportError: No module named test_ui
i've got two script, one for 'func', second for 'ui', is just a test with a pushButton (simply)

This two script are in : 'C:\Users\%USERNAME%\AppData\Roaming\Blackmagic Design\Fusion\Scripts\Comp'
Script Prefs : 'UserPaths:Scripts'

So even i call the modul in script root folder (for fusion), i get this error again :
  1. from Comp.test_ui import Ui_testForm
  2. ImportError: No module named Comp.test_ui
So with this two example, func.py file loaded well by Fu, but when i put an "import" file in, got an error...

Any ideas ?

EDIT : i forgot, i've got studio and this little test work well on windows10 without Fu opened.
Last edited by miaz3 on Thu Sep 20, 2018 12:51 pm, edited 1 time in total.

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#2

Post by miaz3 » Thu Sep 20, 2018 12:28 pm

Try with menu config (create a menu with a python run command), select Python2 Language :
  1. Execute = _Python [=[
  2.           execfile(r'C:\Users\AppData\Roaming\Blackmagic Design\Fusion\Scripts\Comp\test\test_func.py')
  3.         ]=],
i've got the same error :
  1. Traceback (most recent call last):
  2.   File "<nofile>", line 1, in <module>
  3.   File "C:\Users\AppData\Roaming\Blackmagic Design\Fusion\Scripts\Comp\test\test_func.py", line 3, in <module>
  4.     from test_ui import Ui_testForm
  5. ImportError: No module named test_ui

User avatar
Cedric
Posts: 42
Joined: Tue Sep 13, 2016 7:26 am
Location: Ghent
Been thanked: 4 times

Re: [PY2] Import module fail

#3

Post by Cedric » Thu Sep 20, 2018 3:22 pm

Hi Miaz

Not totally sure I understand what you're trying to achieve, but I think the fact that you're in Fusion or not doesn't matter.
Python can't import the modules because they are not present/known in the PYTHONPATH. (Ap/Pre)pend your PYTHONPATH with the directory your scripts are in.
That should work fine to my guess.

Cheers
Cedric

PS: If you want more info on how I manage repositories external to eachother and still have an ecosystem within Fusion, I can elaborate on how I go about doing this. Considering you have a user interface module and unit tests, might be a good idea to look at creating a repo structure, deployed at a specific location under an environment variable known to Fusion and your PATH/PYTHONPATH.

Added in 6 minutes 25 seconds:
I did a little test setup and what I say is correct.
I created two scripts:

  1. class GUI(object):
  2.     pass
  1. from gui import GUI
  2. window = GUI()
  3. print(window)

Both of these scripts are inside my default user Fusion Script location.
I added this directory to my PYTHONPATH and now when I run the launcher from within Fusion's Script dir, I get my print statment in the console.

Code: [Select all] [Expand/Collapse] [Download] (consoleout.py)
  1. <gui.GUI object at 0x0000000002DA6588>

Cheers
Cedric

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#4

Post by miaz3 » Thu Sep 20, 2018 10:52 pm

Hello Cedric,

I'm sorry for being poor at expressing myself, but you're just aiming. That's exactly what I'm trying to do. (CF)
test_ui.py is a UI from QTdeigner and test_func.py is the function.

My python.exe is in my windows Env "Path", i allready add "C:\Users\AppData\Roaming\Blackmagic Design\Fusion\Scripts" to the same Env.

EDIT : I've got python 27, and forced python 27 in Fu too.
You do not have the required permissions to view the files attached to this post.

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#5

Post by miaz3 » Fri Sep 21, 2018 5:00 am

I have not well understood i'll try this tonight.
Creat a 'PYTHONPATH' var instead of putting everything in the PATH system.

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#6

Post by miaz3 » Fri Sep 21, 2018 11:32 am

SO...
I created a PYTHONPATH var with 'C:\Python27;C:\Users\jeremy\AppData\Roaming\Blackmagic Design\Fusion\Scripts\'

and i've got the same issue.
You do not have the required permissions to view the files attached to this post.

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#7

Post by miaz3 » Sat Sep 22, 2018 1:37 pm

I turn around...don't know why Fu can't run this.

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#8

Post by miaz3 » Tue Sep 25, 2018 9:07 am

I tried to print "__file__" before import module on the func.py file:
  1. import os, sys
  2. ROOT = os.path.dirname(os.path.abspath(__file__))
  3. print ROOT
  1. >>>C:\Program Files\Blackmagic Design\Fusion 9
Is weird this path ? no ? normally, it should have returned to me the path of the script folder

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#9

Post by miaz3 » Wed Sep 26, 2018 2:58 am

i forgot, same issue even i forced "__file__" with the script path folder.
  1. import os, sys
  2. ROOT = os.path.dirname(os.path.abspath("C:\Users\jeremy\AppData\Roaming\Blackmagic Design\Fusion\Scripts\Comp\test\test_func.py"))
  3. print ROOT
  4. sys.path.append(ROOT)

User avatar
miaz3
Fusioneer
Posts: 203
Joined: Sat Jan 03, 2015 1:43 am
Location: Angoulême / France
Been thanked: 1 time
Contact:

Re: [PY2] Import module fail

#10

Post by miaz3 » Wed Sep 26, 2018 11:40 am

Fiou ... finally!
- I had to put '__init__' in "Comp" folder
- forced with a sys.append and necessarily import module from Comp Folder 'Comp.test.test_ui'

As i wrote before i've got a windows 10, python & Pyside install...nothing exotic !
seriously, it's bullshit

Cherry on the cake :
if i run script from menu script (eg: post before)
error :
  1. Traceback (most recent call last):
  2.   File "<nofile>", line 1, in <module>
  3.   File "C:\Users\jeremy\AppData\Roaming\Blackmagic Design\Fusion\Scripts\Comp\test\test_func.py", line 62, in <module>
  4.     app = QtGui.QApplication(sys.argv)
  5. RuntimeError: A QApplication instance already exists.
But i allready close the window !

anyway, I'm giving up...script work well now via script menu It's already a good thing.