Visual Studio puts red/green squiggles under 'cv2' and 'mediapipe' imports - python

I am coding in python using Microsoft Visual Studio 2022 and I have import all the libs I need , but Microsoft Visual Studio is saying they are not there when they are.
here is a picture of my setup :
the code runs and works, but both those libs are still highlighted green and The annoying thing about it is, visual Studios "autocode" is not working for those libs. So when I do cv2. nothing comes up.

Related

Installing PyflyCapture2 Python problems with C++ building

I'm currently working on a remote camera control and using a Point Grey fl3-u3-32s2c-cs. I would like to control my camera, retrieve images and so on using Python. FLIR (previously Point Gre) provides FlyCapture, which is the SDK used to work with FLIR USB 2.0, USB 3.0, Gigabit Ethernet or FireWire cameras. Since I want to work exclusively with Python, I found the python package pyflycapture2 that would fit my needs. However, when I tried to install the python package pyflycapture2, I got the error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools". And that's what I did: Download Microsoft Build Tools for Visual Studio, then I selected Workloads → Desktop development with C++, then for Individual Components, I selected only Windows 10 SDK and C++ x64/x86 build tools.
When I try to run pip install pyflycapture in the command line, I get the following error message (shown in the image file):
Error message when running pip install pyflycapture2
By lookin at the error message, it seems that it couldn't find the c++ file, in fact one part of the error says: src\flycapture2.c(235): fatal error C1083: Cannot open include file: 'FlyCapture2Defs_C.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
I have added the folder where I installed visual studio and where the building tools in c++ are installed into the path, but for some reason I keep getting the same error. I’m working with Windows 10 andq 64-bit operating system, x64-based processor. Any hwlp would be greatly appreciated, thank you.

install METIS library for python3 on windows7

I want to install METIS for python3.6 on windows7.I did the following steps:
1-Download the source (tar.gz or zip file) from
https://pypi.python.org/pypi/networkx-metis/
2-Unpack and change directory to the source directory (it should have the
setup.py on top level).
3-Run
python setup.py build
to build
in this step, I encountered the following error:
error: Microsoft Visual C++ 14.0 is required.
i installed "Visual Studio Tools 2017", Then I run the code again. I encountered the following error:
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio
14.0\\VC\\BIN\\cl.exe' failed with exit status 2
I would be very grateful if you answer my questions.
Although what I used was Windows 10, perhaps the same steps as I laid out here may work for you.
First, you should get the python metis wrapper using pip: pip install metis.
Second, you must install conda-metis, which you can find here. Note, it does not require you to install Anaconda to work.
Place the files in conda-metis-master in some file path.
The installation requires some fixes. Make sure you have a recent version of Visual Studios (I used 2017). For me, VS had a problem running the instructions in BUILD-WINDOWS.txt, which landed me on this thread:
Why does MSBuild look in C:\ for Microsoft.Cpp.Default.props instead of c:\Program Files (x86)\MSBuild? ( error MSB4019)
Specifically, the answer For Visual Studio 2017 and 2019 on Windows 10 was what I went with. It could potentially be different for you since you are on Windows 7.
For the python metis package, we need to generate a metis.dll, not a metis.lib file, so we must also look closer at the CMakeLists.txt (see the Linux version of this discussion here). We add on line 19: set(METIS_LIBRARY_TYPE SHARED).
You should follow the BUILD-WINDOWS.txt instructions, but run .\vsgen -G "Visual Studio 15 2017 Win64" inside your conda-metis file path in command prompt with full permissions instead of using Visual Studio 10.
Before moving on to using the files that were generated by the above command in path_to_your_metis_dir\build\windows\, we need another fix. Following what was said in:
rint() issue after creating VS Project using CMake
we have to edit the file path_to_your_metis_dir\GKlib\gk_arch.h by removing the line: #define rint(x) ((idx_t)((x)+0.5)). (Or the fix listed on this github exchange.)
Then go to path_to_your_metis_dir\build\windows\.
Open METIS.sln in Visual Studios, go to the top to Build and from the scroll-down go to Build Solution. Afterwards, the .dll file will be in path_to_your_metis_dir\build\windows\libmetis\Release\.
Last, we run in command prompt:
set METIS_DLL=path_to_your_metis_dir\build\windows\libmetis\Release\metis.dll
After this, python metis no longer failed when I would import it into my code with the step from metis import *.

Spyder does not recognise cython modules when importing in a script

I have got a cython script example1.pyx with various functions. I am trying to use one of these functions in my python script. To do this I am simply trying to import the function from the cython module as follows:
from example1 import myfunction1
I am using Spyder to run my python script. When I run it I get the following error
ModuleNotFoundError: No module named 'example1'
for some reason, .pyx extension scripts are not recognised as modules that can be imported. I can successfully import other python scripts, but no luck with cython .pyx scripts. Turns out I wasnot compiling the python script. So I did so using the following script:
from setuptools import setup, Extension
import numpy
from Cython.Distutils import build_ext as _build_ext
list_pyx = ['cydtw', 'cygak', 'cycc', 'soft_dtw_fast']
ext = [Extension(
'%s' % s, ['%s.pyx' % s], include_dirs=[numpy.get_include()]
) for s in list_pyx]
setup(
include_dirs=[numpy.get_include()],
ext_modules=ext,
cmdclass={'build_ext': _build_ext},
)
when I ran this, I got the error saying I need Visual C++ 14.0 compiler. Looking at documentation in https://wiki.python.org/moin/WindowsCompilers, Visual Studio 15 which I have installed already should have Visual C++ 14.0 so that was confusing. So I updated my setuptools. Got rid of that error, but turns out I it cant find a file path C;\program files\Microsoft SDKs\Windows\v8.1\lib. which I can see it doesn't. So that's where I am stuck now. Any clues?
Managed to resolve the issue. Didn't have the Visual C++ compiler installed on Visual Studio 2015.
To check, Open up Visual Studio 15.
Look at Templates under Visual C++.
I could see Visual C++ 2015 Tools for Windows Desktop which needed installing.
This includes tools and libraries for Windows Desktop, which includes the compiler, the Universal CRT and the windows 8.1 SDK. Ran the installation. It will ask you close visual studio in the meantime.
Was able to compile the cython scripts as well as call the functions in the script in my python project.
What I would say you have to be careful about your compiler version and python version matching up. There can be compatibility issues.
Details on Visual Studio Build Tools are available here:
https://landinghub.visualstudio.com/visual-cpp-build-tools
For installing non-pure python packages or compile a cython or pyrex file, the details in terms of compatibility are here:
https://wiki.python.org/moin/WindowsCompilers

Unable to find vcvarshall.bar in Python 3.5

How can I get rid of this error:-
unable to find vcvarshall.bat
I am trying to compile animation nodes 2.0 addon for blender 32 bit, I can't find 32 bit version of the addon, it doesn't have wheel, I have installed anaconda, created Python 3.5 environment, Visual Studio Community 2017, visual c++ 2015 and 2017 and updated setup tools yet I still get "unable to find vcvarshall.bat"
Python 3.6 compiles the addon, but blender isn't able to accept it!
Please advise how to avoid the above error in Python 3.5.
I got it.
I installed visual c++ build tools from here: http://go.microsoft.com/fwlink/?LinkId=691126
and then i ran animation nodes 2.0 addon using x86 native command prompt which can be found in start -> all programs -> visual studio 2017 -> VC.
When i run it through default command prompt, it shows error!

Error: "MSVCP90.dll: No such file or directory" even though Microsoft Visual C++ 2008 Redistributable Package is installed

I'm trying to build a package from source by executing python setup.py py2exe
This is the section of code from setup.py, I suppose would be relevant:
if sys.platform == "win32": # For py2exe.
import matplotlib
sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")
base_path = ""
data_files = [("Microsoft.VC90.CRT", glob.glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")),
Error it shows:
*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory
But I've installed "Microsoft Visual C++ 2008 Redistributable Package". I'm running 32-bit python on 64-bit Windows 8. I'm trying to build a 32-bit binaries.
Also there is no folder like this: "C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\". This is what my computer contains:
EDIT:
On searching for msvcp90.dll on my C:\ drive I found that they are installed in weird paths like this:
I would recommend ignoring the dependency outright. Add MSVCP90.dll to the list of dll_excludes given as an option to py2exe. Users will have to install the Microsoft Visual C++ 2008 redistributable. An example:
setup(
options = {
"py2exe":{
...
"dll_excludes": ["MSVCP90.dll", "HID.DLL", "w9xpopen.exe"],
...
}
},
console = [{'script': 'program.py'}]
)
(new answer, since the other answer describes an alternate solution)
You can take the files from the WinSxS directory and copy them to the C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT directory (normally created by Visual Studio, which you don't have). Copy them to get the following structure:
+-Microsoft.VC90.CRT
| |
| +-Microsoft.VC90.CRT.manifest
| +-msvcm90.dll
| +-msvcp90.dll
| +-msvcr90.dll
Then, you should be able to run the setup program (still excluding msvcp90.dll, as in the other answer), and it should successfully find the files under Microsoft.VC90.CRT and copy them as data files to your bundle.
See the py2exe tutorial for more information.
I used to have a huge number of problems with complication on Windows, like the issue you're facing as well as installing packages like Cython with pip install cython.
The solution that worked best for me after two weeks of pain was downloading and running the unofficial MinGW GCC binary for Windows provided here. You might want to try giving that a shot and seeing if it helps.
If you do do it, you might want to uninstall MinGW if you have it already. I don't know if that's strictly necessary, but I always did it just in case. I did have it installed side-by-side with Cygwin without any problems.
I think it has something to do with the spaces in the directory. You should try using .rstrip(). For example, put this:
directory='C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT'
directory=directory.rstrip()
You can then use the variable directory like you would have used the actual path.
This should make python able to recognize the directory where it wouldn't be able to decipher it before.

Categories