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

Compiling openCV #306

Closed
asknask opened this issue Mar 27, 2020 · 7 comments
Closed

Compiling openCV #306

asknask opened this issue Mar 27, 2020 · 7 comments

Comments

@asknask
Copy link

asknask commented Mar 27, 2020

I was following the directions given in another thread here (#126 (comment)).

  • I installed Git.
  • I cloned this repo
  • I cloned the OpenCV repo
  • I copied the files from the OpenCV repo into the opencv folder of this repo
  • I set a temporary environment variable as mentioned (set CMAKE_ARGS "-DOPENCV_ENABLE_NONFREE=ON")
  • I then executed the python code from this repository as mentioned

I'm getting the following error now:

python setup.py bdist_wheel
fatal: not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
  File "setup.py", line 397, in <module>
    main()
  File "setup.py", line 64, in main
    package_version = get_opencv_version()
  File "setup.py", line 351, in get_opencv_version
    runpy.run_path("find_version.py")
  File "C:\Program Files\Python38\lib\runpy.py", line 263, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Program Files\Python38\lib\runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Program Files\Python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "find_version.py", line 26, in <module>
    git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
  File "C:\Program Files\Python38\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Program Files\Python38\lib\subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', 'rev-parse', '--short', 'HEAD']' returned non-zero exit status 128.
@skvark
Copy link
Member

skvark commented Mar 27, 2020

Well, the fatal: not a git repository (or any of the parent directories): .git kinda tells you the issue: it seems that you didn't clone the repo correctly. Hard to say without exact commands. And you don't need to copy the OpenCV repository, it's included as a submodule in this repository so you'll have to just call git clone --recursive to clone the files in to the opencv and opencv_contrib folders.

@asknask
Copy link
Author

asknask commented Mar 28, 2020

Well, the fatal: not a git repository (or any of the parent directories): .git kinda tells you the issue: it seems that you didn't clone the repo correctly. Hard to say without exact commands. And you don't need to copy the OpenCV repository, it's included as a submodule in this repository so you'll have to just call git clone --recursive to clone the files in to the opencv and opencv_contrib folders.

Thank you for the swift reply.

My mistake yeah. Once I posted the issue, and it was formatted properly, I saw that error (it was hard to spot in cmd).

I cloned the repo correctly and ran it again. Got a cmake error so I installed cmake. Now I'm getting an MSBuild error. I'm assuming I need Visual Studio installed to get this done?

It'd be nice to have all these prerequisites mentioned somewhere.

@asknask
Copy link
Author

asknask commented Mar 28, 2020

After a few hours of trial and error, finally managed to compile it.

Here's a little to-do list for anyone who faces this issue:

  • Install cmake
  • Install Visual Studio 2019 with the Python environment selected. Make sure to check the optional Python compile tools
  • Open the setup.py file with a text editor (Sublime in my case) and edit line 100 to this:
    "-G", "Visual Studio 16 2019"
  • Open cmd as administrator and type the following:
    set CMAKE_ARGS "-DOPENCV_ENABLE_NONFREE=ON"

And now finally, run the python setup.py bdist_wheel command.

Good luck.

@asknask
Copy link
Author

asknask commented Mar 28, 2020

Well, the fatal: not a git repository (or any of the parent directories): .git kinda tells you the issue: it seems that you didn't clone the repo correctly. Hard to say without exact commands. And you don't need to copy the OpenCV repository, it's included as a submodule in this repository so you'll have to just call git clone --recursive to clone the files in to the opencv and opencv_contrib folders.

What steps to I need to take after the compile process is complete, to make sure the opencv python stuff is accessible?

@skvark
Copy link
Member

skvark commented Mar 28, 2020

Yes, you need Visual Studio / compilation tools (Cmake can be installed for example with pip install cmake) to build OpenCV.

The wheel package is generated to the dist folder. You can install it with pip: pip install wheel_package_name.whl.

@asknask
Copy link
Author

asknask commented Mar 28, 2020

Done. Thank you.

@asknask asknask closed this as completed Mar 28, 2020
@ghost
Copy link

ghost commented Apr 7, 2020

λ python setup.py bdist_wheel
Version: 4.2.0+d608d69
setup.py:85: DeprecationWarning: SO is deprecated, use EXT_SUFFIX
['python/cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],


-- Trying "Visual Studio 16 2019" generator






--
Not searching for unused variables given on the command line.
CMake Error at CMakeLists.txt:2 (PROJECT):
Generator

Visual Studio 16 2019

could not find any instance of Visual Studio.

-- Configuring incomplete, errors occurred!
See also "C:/Users/Firoz/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeOutput.log".







-- Trying "Visual Studio 16 2019" generator - failure


scikit-build could not get a working generator for your system. Aborting build.

Building windows wheels for Python 3.8 requires Microsoft Visual Studio 2017.
Get it with "Visual Studio 2017":

can any one please help because. i can not run the same. showing the above error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants