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

Windows: Import error after pip install #813

Closed
Tilix4 opened this issue Oct 9, 2020 · 44 comments · Fixed by #950
Closed

Windows: Import error after pip install #813

Tilix4 opened this issue Oct 9, 2020 · 44 comments · Fixed by #950
Assignees
Labels
build issues building OTIO windows

Comments

@Tilix4
Copy link
Contributor

Tilix4 commented Oct 9, 2020

Bug Report

-- edit: removed the checkboxes so that GitHub is no longer confused about open tasks --

  • Incorrect functionality

Describe the bug here. If it is a build issue, please note whether the issue was encountered via cmake, pip, or tox.

To Reproduce

  1. Operating System: Windows 10
  2. Python 3.7.9, CMake installed
  3. Example snippet that demonstrates the issue:
ImportError: DLL load failed: The specified module could not be found.
  1. OpenTimelineIO 0.13.0

Expected Behavior

The import statement to work correctly.

Logs

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\User\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\User\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\User\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "E:\Logiciels\Stax\Dev\stax\test_otio.py", line 4, in <module>
    import opentimelineio as otio
  File "e:\Logiciels\Stax\Dev\stax\.venv\lib\site-packages\opentimelineio\__init__.py", line 35, in <module>
    from . import (
  File "e:\Logiciels\Stax\Dev\stax\.venv\lib\site-packages\opentimelineio\opentime.py", line 1, in <module>
    from . _opentime import ( # noqa
ImportError: DLL load failed: The specified module could not be found.
@Tilix4 Tilix4 added the bug A problem, flaw, or broken functionality. label Oct 9, 2020
@apetrynet
Copy link
Contributor

apetrynet commented Oct 9, 2020

Hi @Tilix4 !
I suspect this is an issue that's popped up once in awhile. Have you tried the workaround mentioned in this issue? #770 (comment)

@Tilix4
Copy link
Contributor Author

Tilix4 commented Oct 12, 2020

Hi @apetrynet I've read this thread, but I cannot find site-packages\opentimelineio\cxx-libs, this directory doesn't exist. I did search for .dll but I didn't find any.

I'm installing with pip's --target option.

@apetrynet
Copy link
Contributor

Hmm. OK, good you checked the other issues.
I don't have enough experience with OTIO on windows or usage of the --target option so I'll pass this on to @reinecke and @meshula. Could any of you shed some light on this?

@meshula
Copy link
Collaborator

meshula commented Oct 14, 2020

What command line did you use to do the pip install? I notice that you used --target, but it's hard to guess what's going on without the whole command line.

@apetrynet
Copy link
Contributor

I noticed blender in there. Could it be related to #667?

@Tilix4
Copy link
Contributor Author

Tilix4 commented Oct 14, 2020

My command line is very basic: python -m pip install --target /path/to/dir opentimelineio.

@apetrynet I've also tried with the Blender python, but I have the same issue with the windows python only, then Blender is not a topic for now ;)

@donquibeats
Copy link

I am getting the same error message under different circumstances. I'm using OpenTimelineIO 0.13.0 in a Python script, and using PyInstaller to bundle it up as an .exe for use around the studio. When bundled, running the .exe on a different machine throws this error:

File "venv\lib\site-packages\opentimelineio\opentime.py", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

As far as I can tell (and I'm not confident about this), either PyInstaller or the frozen OpenTimelineIO code isn't coping properly with the relative path inherent in the line from . _opentime import (

Short of an update to OpenTimelineIO, might anyone be able to suggest an adjustment to this opentime.py file that would make it PyInstaller-friendly please? I'm not familiar with the structure of the code within site-packages/opentimelineio.

@reinecke
Copy link
Collaborator

@donquibeats pyinstaller can be a bit tricky. I think there is a way to unzip the contents of a pyinstaller archive, are you able to find the DLLs in there?
It's been a while, but last time I worked with pyinstaller I found that it had some setuptools tricks going on that sometimes could make it tough to ensure the extra non-puython resources would reliably be relocated into the package.

Also, which python version are you using to build the pyinstaller package?

@donquibeats
Copy link

Thanks for the responses. This is a Python 3.7 project, and PyInstaller creates a folder containing the .exe and a bunch of associated DLL's, but opentime.py and opentimelineio.py are not among them.

However, copying these DLL's manually from cxx-libs/bin into the same folder as the .exe doesn't fix the problem, unfortunately.

I'm not currently aware of how I would test whether the DLL's are bundled inside the .EXE.

Strangely, if we target OpenTimelineIO 0.11.0 then it works fine. This error only occurs if we target 0.12.x or 0.13.0. We can make it work if we accept the older version of OTIO (via pypi).

@apetrynet
Copy link
Contributor

Strangely, if we target OpenTimelineIO 0.11.0 then it works fine. This error only occurs if we target 0.12.x or 0.13.0. We can make it work if we accept the older version of OTIO (via pypi).

0.11.0 was the last pure python release which is probably why it works out of the box. Other than that I'm afraid I can't be of any more help on this issue.

@donquibeats
Copy link

Thanks. Does the fact that 0.11.0 works give any indicators, either of what the problem might be, or of a possible workaround that we could use? For our current needs 0.11.0 is OK, but obviously we wouldn't want to be stuck on the older version forever.

@apetrynet
Copy link
Contributor

Please excuse me if this is obvious to you :)
OTIO >=0.12.0 are based on a C++ core while <= 0.11.0 are strictly python based. The C++ based versions have python bindings built against library files. I think the main issue here is that the library files aren't installed to a location where python by default can get a hold of them.
To sum up. 0.11.0 is self contained while 0.12+ rely on library files (so or dll).

I believe @meshula is cooking up a cleaner install OTIO and the python bindings that hopefully will help.

@donquibeats
Copy link

That makes sense, thanks very much for the explanation.

In the short term, when I get time I will try again to use 0.13.0 via PyInstaller by embedding the two DLL files manually and adapting the import code, to see if I can put them somewhere that a PyInstaller-bundled Python can see them.

@reinecke
Copy link
Collaborator

Hey @donquibeats, here are a couple useful references for this stuff in pyinstaller:

  • This tool may be able to help you inspect what got packaged in your .exe to see if stuff is missing
  • If there is, in fact, something not being included that should be, the spec file may help with making sure those things get included

Forgive me if I'm covering stuff you already know. In my past struggles with PyInstaller, I remember these two bits being key for solving the problem I had.

@meshula
Copy link
Collaborator

meshula commented Oct 21, 2020

Have you tried adding your PYTHONPATH to your PATH variable? A similar thread about USD pyd loading was resolved by doing so.

@donquibeats
Copy link

Firstly, really sorry it took me a month to even see these replies. I got pulled onto a different bit of the project and have only just looped round to this question.

I remain stuck in the same position as before though, in fact it's a little worse. I am trying to do AAF and XML exports from an Otio object, but in OTIO 0.11.0 it throws errors that don't get thrown by 0.13.0. However, I can't successfully use PyInstaller to compile an .EXE using 0.13.0 (the error I reported in a previous post on this thread), but I can compile fine if I use 0.11.0. So I'm stuck.

From the suggestion by @reinecke I've just run pyi-archive_viewer on my compiled versions, and the list of items beginning opentimelineio is the same in both versions- 42 items, which I've pasted below.

We do use .spec files for the PyInstaller compilation, and have added_files parameters where I could manually tell PyInstaller to bring in specific files, but the problem is I don't understand which files are missing and need to be brought in.

I'm not sure how to apply the suggestion from @meshula since PyInstaller is meant to handle all the Python bundling and path pointing, and the rest of the Python libraries work fine, this remains a problem specific to OpenTimelineIO version 0.12.0 or above.

Any further suggestions would be very welcome.

'opentimelineio',
'opentimelineio.adapters',
'opentimelineio.adapters.adapter',
'opentimelineio.adapters.otio_json',
'opentimelineio.algorithms',
'opentimelineio.algorithms.filter',
'opentimelineio.algorithms.stack_algo',
'opentimelineio.algorithms.timeline_algo',
'opentimelineio.algorithms.track_algo',
'opentimelineio.core',
'opentimelineio.core.composable',
'opentimelineio.core.composition',
'opentimelineio.core.item',
'opentimelineio.core.json_serializer',
'opentimelineio.core.media_reference',
'opentimelineio.core.serializable_object',
'opentimelineio.core.type_registry',
'opentimelineio.core.unknown_schema',
'opentimelineio.exceptions',
'opentimelineio.hooks',
'opentimelineio.media_linker',
'opentimelineio.opentime',
'opentimelineio.plugins',
'opentimelineio.plugins.manifest',
'opentimelineio.plugins.python_plugin',
'opentimelineio.schema',
'opentimelineio.schema.clip',
'opentimelineio.schema.effect',
'opentimelineio.schema.external_reference',
'opentimelineio.schema.gap',
'opentimelineio.schema.generator_reference',
'opentimelineio.schema.marker',
'opentimelineio.schema.missing_reference',
'opentimelineio.schema.schemadef',
'opentimelineio.schema.serializable_collection',
'opentimelineio.schema.stack',
'opentimelineio.schema.timeline',
'opentimelineio.schema.track',
'opentimelineio.schema.transition',
'opentimelineio.schemadef',
'opentimelineio_contrib',
'opentimelineio_contrib.adapters',

@donquibeats
Copy link

Just to update, I have logged a new issue #838 for the problem I was having as it now seems quite different to the original point of this issue #813

@donquibeats
Copy link

With help, I found a fix/workaround for the issue that I spun off as #838

Apologies for hijacking this similar issue to start with.

I don't know whether the original problem of this issue #813 is still outstanding for other people?

@meshula meshula self-assigned this Dec 16, 2020
@meshula meshula mentioned this issue Dec 16, 2020
@Tilix4
Copy link
Contributor Author

Tilix4 commented Jan 8, 2021

This will be closed by #837!

Thanks to @meshula

@Tilix4
Copy link
Contributor Author

Tilix4 commented Feb 17, 2021

@meshula Re-opening this discussion.

Doing python -m pip install git+https://github.com/PixarAnimationStudios/OpenTimelineIO.git on Windows now gives me:

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Felix\AppData\Local\Temp\pip-req-build-zi_ro1tk\setup.py", line 454, in <module>
        **PROJECT_METADATA
      File "C:\Users\Felix\AppData\Roaming\Python\Python37\site-packages\setuptools\__init__.py", line 129, in setup
        return distutils.core.setup(**attrs)
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Felix\AppData\Local\Temp\pip-req-build-zi_ro1tk\setup.py", line 157, in run
        install.run(self)
      File "C:\Users\Felix\AppData\Roaming\Python\Python37\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\Felix\AppData\Local\Temp\pip-req-build-zi_ro1tk\setup.py", line 176, in run
        self.build()
      File "C:\Users\Felix\AppData\Local\Temp\pip-req-build-zi_ro1tk\setup.py", line 192, in build
        cmake_generate()
      File "C:\Users\Felix\AppData\Local\Temp\pip-req-build-zi_ro1tk\setup.py", line 114, in cmake_generate
        env=os.environ.copy()
      File "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\lib\subprocess.py", line 363, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Felix\\AppData\\Local\\Temp\\pip-req-build-zi_ro1tk', '-DPYTHON_EXECUTABLE=E:\\Logiciels\\Stax\\Dev\\blender-2.92.0-c13754e6475e-windows64\\2.92\\python\\bin\\python.exe', '-DOTIO_PYTHON_INSTALL:BOOL=ON', '-DOTIO_CXX_INSTALL:BOOL=ON', '-DCMAKE_BUILD_TYPE=Release', '-DOTIO_PYTHON_INSTALL_DIR=E:\\Logiciels\\Stax\\Dev\\blender-2.92.0-c13754e6475e-windows64\\2.92\\python\\Lib\\site-packages', '-DCMAKE_INSTALL_PREFIX=E:\\Logiciels\\Stax\\Dev\\blender-2.92.0-c13754e6475e-windows64\\2.92\\python\\Lib\\site-packages\\opentimelineio\\cxx-libs', '-DOTIO_PYTHON_PACKAGE_DIR=E:\\Logiciels\\Stax\\Dev\\blender-2.92.0-c13754e6475e-windows64\\2.92\\python\\Lib\\site-packages', '-A', 'x64']' returned non-zero exit status 1.

    ----------------------------------------
Command "E:\Logiciels\Stax\Dev\blender-2.92.0-c13754e6475e-windows64\2.92\python\bin\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Felix\\AppData\\Local\\Temp\\pip-req-build-zi_ro1tk\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Felix\AppData\Local\Temp\pip-record-5y35882f\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Felix\AppData\Local\Temp\pip-req-build-zi_ro1tk\

Full message in:
otio_bug_windows_log.txt

@meshula
Copy link
Collaborator

meshula commented Feb 17, 2021

More info: I see in your log that pybind11 is failing to find Python...

    -- Found PythonInterp: E:/Logiciels/Stax/Dev/blender-2.92.0-c13754e6475e-windows64/2.92/python/bin/python.exe (found version "3.7.7")
    CMake Error at src/deps/pybind11/tools/FindPythonLibsNew.cmake:158 (message):
      Python libraries not found
    Call Stack (most recent call first):
      src/deps/pybind11/tools/pybind11Tools.cmake:16 (find_package)
      src/deps/pybind11/CMakeLists.txt:33 (include)

@meshula meshula added build issues building OTIO windows and removed bug A problem, flaw, or broken functionality. labels Feb 17, 2021
@Tilix4
Copy link
Contributor Author

Tilix4 commented Feb 17, 2021

I also tested with: #886

I get the same error.

@Tilix4
Copy link
Contributor Author

Tilix4 commented Feb 17, 2021

More info: I see in your log that pybind11 is failing to find Python...

But two lines above it says -- Found PythonInterp: E:/Logiciels/Stax/Dev/blender-2.92.0-c13754e6475e-windows64/2.92/python/bin/python.exe, this isn't related?

@meshula
Copy link
Collaborator

meshula commented Feb 17, 2021

yes, that's related. It's Python's libs it didn't find

@meshula
Copy link
Collaborator

meshula commented Feb 17, 2021

conda create -n otio37 python=3.7
conda activate otio37
python -m pip install git+https://github.com/PixarAnimationStudios/OpenTimelineIO.git 

yields

(otio37) c:\Projects\otio>python -m pip install git+https://github.com/PixarAnimationStudios/OpenTimelineIO.git
Collecting git+https://github.com/PixarAnimationStudios/OpenTimelineIO.git
  Cloning https://github.com/PixarAnimationStudios/OpenTimelineIO.git to c:\users\meshu\appdata\local\temp\pip-req-build-bdywgop8
Collecting pyaaf2==1.4.0
  Downloading pyaaf2-1.4.0.tar.gz (88 kB)
     |████████████████████████████████| 88 kB 897 kB/s
Building wheels for collected packages: OpenTimelineIO, pyaaf2
  Building wheel for OpenTimelineIO (setup.py) ... done
  Created wheel for OpenTimelineIO: filename=OpenTimelineIO-0.14.0.dev1-cp37-cp37m-win_amd64.whl size=277724 sha256=9bd3ed0643240bbca643137f5a907db89594a0f53b3882f5f4d3ace38703aeb0
  Stored in directory: C:\Users\meshu\AppData\Local\Temp\pip-ephem-wheel-cache-nj0hrtss\wheels\a9\91\fc\01fdbe84d389b72f61a5f30145d64dd00d87a77b772b448aa1
  Building wheel for pyaaf2 (setup.py) ... done
  Created wheel for pyaaf2: filename=pyaaf2-1.4.0-py3-none-any.whl size=99181 sha256=31261fcd4395f2aecd01148a95a2c8783dd2adc6ce0c969028da3416ee1631ce
  Stored in directory: c:\users\meshu\appdata\local\pip\cache\wheels\31\d3\d1\ea021cecc69fb573e5c0b2d71ea8897b71d9e30b7596ba2b14
Successfully built OpenTimelineIO pyaaf2
Installing collected packages: pyaaf2, OpenTimelineIO
Successfully installed OpenTimelineIO-0.14.0.dev1 pyaaf2-1.4.0

There must be something different about where the Python libraries are located for Blender. Do you know where they are?

@meshula
Copy link
Collaborator

meshula commented Feb 18, 2021

Following the instructions on the blender website, I see the libraries land in

c:\blender-git\lib\win64-vc15\python\37\libs and 39\libs

to make this work, there probably needs to be a way to pass an argument to pip to tell it where this directory is, and then pass the location from pip to cmake, such that find_package(Python) can subsequently discover the libraries.

We are working through enabling CI for Windows builds at the moment. I think it makes sense to first get our CI working, then address specific build issues such as this one as a second step.

@meshula
Copy link
Collaborator

meshula commented Feb 18, 2021

Further reference: Installing into Blender is documented in @Tilix4 's project: https://gitlab.com/Tilix4/vse-io

@Tilix4
Copy link
Contributor Author

Tilix4 commented Feb 18, 2021

There isn't any way to tell CMake to take the current running python? Because I've launched pip using the Blender's internal python, CMake doesn't handle any reference to it?
Or maybe am I totally misunderstanding the issue...

Further reference: Installing into Blender is documented in @Tilix4 's project: https://gitlab.com/Tilix4/vse-io

Actually I wrote this before testing it, and I raised the issue after my tests. Then this is not a way to make it work...

@meshula
Copy link
Collaborator

meshula commented Feb 18, 2021

CMake is properly finding the runtime components. It isn't finding the python.lib for linking with C++. That's the failure. Blender puts the python linking libraries in a different place than the CMake Python find script expects. That's why I'm saying we would need to tell CMake where the Blender build puts the linking library in particular. The rest is fine.

@ginwakeup
Copy link

Hey, I am experiencing similar issues to some comments in the thread.
I've installed opentimelineIO in a simple python 3.7 project, as soon as I try to import opentimelineIO I get the following exception:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "X:\techart\venv3.7.3\lib\site-packages\opentimelineio\__init__.py", line 35, in <module>
    from . import (
  File "X:\techart\venv3.7.3\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
  File "X:\techart\venv3.7.3\lib\site-packages\opentimelineio\opentime.py", line 1, in <module>
    from . _opentime import ( # noqa
  File "X:\techart\venv3.7.3\lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
    return original_import(name, *args, **kwargs)
ImportError: DLL load failed: The specified module could not be found.

Any idea on how can I solve this?

@Tilix4
Copy link
Contributor Author

Tilix4 commented Mar 31, 2021

Hi @meshula, Any news about this?

@meshula
Copy link
Collaborator

meshula commented Mar 31, 2021

Hi there, thanks for the follow up. In the last month or so, we've put some effort into making the Python set up easier to manage. None of us currently build Blender, so we haven't tested that yet. If you don't specify OTIO_PYTHON_INSTALL_DIR or a CMAKE_INSTALL_PREFIX, the OTIO build system will attempt to set up python according to the cmake standard command:

        find_package(Python REQUIRED COMPONENTS Interpreter Development)

So at this point, my expectation would be that if you don't override those two variables, and you do follow standard Blender/cmake guidance for find_package(Python), things should work. I am being a little vague and optimistic about standard guidance on Blender/cmake, because I hope there is some, but haven't found it yet. If you know where that is, we could do a test and verify if my expectation makes sense.

@Tilix4
Copy link
Contributor Author

Tilix4 commented Mar 31, 2021

Thanks for this information.

I'm not sure but maybe there is a misunderstanding. I'm not talking about building Blender with OTIO, but installing OTIO into the embedded python of Blender. Something like: /path/to/blender_python_exec -m pip install git+https://github.com/PixarAnimationStudios/OpenTimelineIO.git, which was working until 0.11.0 but doesn't since.

Then to try it you may download any windows portable Blender version and try this command. It tested today and it still fails.
Tell me if you were actually talking about that, because I don't understand how to have an actual CMake influence from this context.

@meshula
Copy link
Collaborator

meshula commented Mar 31, 2021

To clarify, I have been focused on the cmake side of the problem. Pip uses cmake to install otio. otio uses cmake's find_package to discover details about Python's installation. Therefore to install into Blender, there has to be some way to tell cmake to use Blender's Python, instead of your system blender.

According to what I can find on stackexchange, running pip from blender's python should be sufficient to satisfy find_package, as per the command line you proposed.

According to Blender's issues pages, there was a bug in some versions of cmake 3.17 that prevented find_package(python) from working, but it eventually got fixed, so presumably cmake 3.18 + should be expected to work, but I imagine that's not the problem you are encountering.

So, the possible problems are -

1 - our setup.py does not interpret information received from pip properly
2 - our setup.py reads the information properly but does not pass it to cmake properly
3 - our cmake receives proper information but does not use it properly
4 - an unlucky point release of cmake 3.17

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 19, 2021

Hi @meshula, is there any update about it?

Starting from now I'll spend some time trying to fix this issue and being finally able to pip install OTIO into blender's python.

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 19, 2021

@meshula, first step following https://opentimelineio.readthedocs.io/en/latest/tutorials/quickstart.html#to-build-otio-for-both-c-and-python-development

I get this error on both linux and windows:

Traceback (most recent call last):
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\distutils\fancy_getopt.py", line 233, in getopt
    opts, args = getopt.getopt(args, short_opts, self.long_opts)
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\getopt.py", line 93, in getopt
    opts, args = do_longs(opts, args[0][2:], longopts, args[1:])
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\getopt.py", line 157, in do_longs
    has_arg, opt = long_has_args(opt, longopts)
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\getopt.py", line 174, in long_has_args
    raise GetoptError(_('option --%s not recognized') % opt, opt)
getopt.GetoptError: option --cxx-install-root not recognized

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 36, in <module>
    _dist.parse_command_line()
  File "C:\Users\Felix\AppData\Roaming\Python\Python37\site-packages\setuptools\dist.py", line 499, in parse_command_line
    result = _Distribution.parse_command_line(self)
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 483, in parse_command_line
    args = self._parse_command_opts(parser, args)
  File "C:\Users\Felix\AppData\Roaming\Python\Python37\site-packages\setuptools\dist.py", line 814, in _parse_command_opts
    nargs = _Distribution._parse_command_opts(self, parser, args)
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 578, in _parse_command_opts
    (args, opts) = parser.getopt(args[1:])
  File "C:\Users\Felix\AppData\Local\Programs\Python\Python37\lib\distutils\fancy_getopt.py", line 235, in getopt
    raise DistutilsArgError(msg)
distutils.errors.DistutilsArgError: option --cxx-install-root not recognized

@meshula
Copy link
Collaborator

meshula commented Apr 19, 2021

Thanks for the report. Unfortunately, the documentation wasn't updated when we recently updated the pip set up to interact more naturally with cmake. The cxx-install-root option is no longer wired up. Could you try again with python setup.py install? We need to update readthedocs...!

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 20, 2021

Thanks, it worked. I'm digging into pip issue.

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 20, 2021

Daily report:
I can compare the successful (windows python3.7.9) and the failing one (blender python 3.7.7).

The weels building bdist_wheel fails in both cases and falls back on the install.

It seems to be an issue in the src\deps\pybind11\tools\FindPythonLibsNew.cmake, the PYTHON_LIBRARY var is always deduced from the python's executable and infers filepaths only on windows which cannot be overriden: https://github.com/pybind/pybind11/blob/8de7772cc72daca8e947b79b83fea46214931604/tools/FindPythonLibsNew.cmake#L184

These directories don't exist under Blenders python:

python/
|
|--bin/
  |--python.exe 
  |--python37.dll
|--DLLs/...
|--lib/...

Setting by hand directly in the code PYTHON_LIBRARY to the lib/ dir works and the libs are correctly found, but leads to a new error:

CMake Error in src/py-opentimelineio/opentime-bindings/CMakeLists.txt:
      Imported target "pybind11::module" includes non-existent path

        "E:/Logiciels/Stax/Dev/blender-2.92.0-windows64/2.92/python/include"

      in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

      * The path was deleted, renamed, or moved to another location.

      * An install or uninstall procedure did not complete successfully.

      * The installation package was faulty and references files it does not
      provide.

Which looks like a similar issue, where the include dir is supposed to be there by default but doesn't exist on blender's python.

Trying to disable the PYTHON_INCLUDE_DIR (set empty) leads to these issues (sharing in case it pops up something to your mind):

WARNING: Target "_opentime" requests linking to directory "E:/Logiciels/Stax/Dev/blender-2.92.0-windows64/2.92/python/lib".  Targets may link only to libraries.  CMake is dropping the item.
...
C:\Users\Felix\AppData\Local\Temp\pip-req-build-_i66ief9\src\deps\pybind11\include\pybind11\detail/common.h(124,10): fatal error C1083: Cannot open include file: 'Python.h': No such file or directory

Hope the information is useful, will continue my cluedo tomorrow.

@meshula
Copy link
Collaborator

meshula commented Apr 20, 2021

Great progress, congratulations. As part of your process, I would recommend looking at your CMakeCache.txt. You can discover (1) what are the names of variables actually in use, and (2) how do the things you set relate to where they landed in the CMakeCache. It's a shame the Python ecosystem is so complex, but I guess it's to be expected after decades of experimentation by the community.

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 21, 2021

Okay, I managed to install into Blender's python by setting PYTHON_INCLUDE_DIRS and PYTHON_LIBRARIES by hand to target the local python libs and dirs.

Now I have to find a way to correctly target these resources from Blender's python. Do you have any input about pybind which could provide it on its own?
And why it works easily on unix but not on windows?

@meshula
Copy link
Collaborator

meshula commented Apr 21, 2021

By "correctly target these resources" do you mean setting up Blender to also see OpenTimelineIO? I think you can't point outside of Blender - https://blender.stackexchange.com/questions/172421/pythonpath-ignored - but there are a bunch of solutions - https://stackoverflow.com/questions/11161901/how-to-install-python-modules-in-blender

Unfortunately Python on Windows is very prickly compared to other platforms, due to I suppose philosophical differences by the maintainers of different platforms. For example, on Windows, there is a not well documented rule that debug builds of Python need all modules suffixed with a lower case d. There are also difficulties with dynamic library search paths that do not apply on other platforms. You can see similar struggles here PixarAnimationStudios/OpenUSD#1478 and here PixarAnimationStudios/OpenUSD#1420 ....

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 21, 2021

No, I mean to tell the builder to find the system python instead of the current running python for the library and the include directories (which will force to have python3 installed to pip install into blender's python).
i.e:
PYTHON_LIBRARIES=C:/Users/Felix/AppData/Local/Programs/Python/Python37/libs/python37.lib
PYTHON_INCLUDE_DIRS=C:/Users/Felix/AppData/Local/Programs/Python/Python37/include

The other possibility would be to embed all these dependencies into OTIO package but it feels heavy.

@Tilix4
Copy link
Contributor Author

Tilix4 commented Apr 21, 2021

NB: I'm facing the exact same issues with the https://github.com/pybind/cmake_example trying to pip install it into blender's python. I'll try to make it work and then report the modifications into OTIO's.

meshula pushed a commit that referenced this issue Apr 21, 2021
…formation (#950)

* Fix: pip install works for third application's embeded python.
Fix #813

* Added link to documentation

* Fixed trailing whitespace

* FIxed line too long
@jminor jminor added this to the Public Beta 14 milestone Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build issues building OTIO windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants