Category Archives: Python

Windows: PIP Install error: Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat

Just after installing PIP in Windows environment on the machine, it is convenient to use it when installing the package in the future. Who knows that when using pip to install asyncio for the first time, it will report an error

when using PIP installation package under windows7x64, you will be prompted to report an error: Microsoft Visual C + + 9.0 is required (unable to find vcfarsall. Bat)

environment: windows7 x64, python2.7, vs2012

reason: when using PIP installation package under windows, you need VS2008 installed on the machine, but vs2012 is not enough, if you don’t want to install VS2008, You can install a package of Micorsoft Visual C + + compiler for Python 2.7

Python Visual C++ 9.0 is required [Two Method to Solve]

Error: Microsoft Visual C + + 9.0 is required (unable to find vcfarsall. Bat). Get it… Solution

When Python installs some modules through pip or source code, these modules contain C/C + + source code, and the installation process will call the local compiler to compile these codes. The error message when I install on Windows platform is “error: Microsoft Visual C + + 9.0 is required (unable to find vcfarsall. Bat). Get it” fromhttp://aka.ms/vcpython27 ”It can be seen that the error is due to not finding the VC version, which corresponds to VS2008. Of course, one solution is to install this version, but I have already installed vs2015, So I need to modify the default configuration

Solutions

Method 1

first, you can determine the version number of vs installed by yourself. You can check the registry. Under HKLM, software, wow6432node, Microsoft and visual studio, as shown in the figure

there will be multiple subkeys of digital card header. Only the one installed will have the corresponding installdir key. You can see that the vs version I installed is 14.0

open the “Python installation directory/lib/distutils/msvc9compiler. Py” file and find_ Vcvarsall function, add
version = the above version number at the beginning of the function, that is, add “version = 14.0”, so that it can be used

def find_vcvarsall(version):
    """Find the vcvarsall.bat file

    At first it tries to find the productdir of VS 2008 in the registry. If
    that fails it falls back to the VS90COMNTOOLS env var.
    """
    version = 14.0            ##added
    vsbase = VS_BASE % version
    ... ... 

Method 2:
this method is simpler. Add an item vs90comntools in the environment variable with the value of “vs installation path common 7 tools”, as shown in the figure

Open the command line program again and you can use it

Solve the problem of Attributeerror: module ‘SciPy. Misc’ has no attribute ‘imread’

This error occurred when running the code recently-AttributeError: module’scipy.misc’ has no attribute’imread’.
After consulting the online materials, I found that most of the solutions are that the PIL third-party library is not installed. The library name is now Pillow. It is recommended to use the command pip install Pillow to install directly, but my problem is not resolved, and I continue to report AttributeError. : module’scipy.misc’ has no attribute’imread’.

After inquiries and attempts, it was found that it was a scipy version problem, and it could be solved perfectly by downgrading to scipy==1.2.1.
The command is as follows:
pip install scipy==1.2.1

 

AttributeError: module ‘cv2’ has no attribute ‘SIFT’ [How to Solve]

AttributeError: module ‘cv2’ has no attribute ‘SIFT’

When encountering this problem, most netizens suggest to add a package, that is, PIP install opencv contrib python.
I made the following error again after completing the repair:
opencv (3.4.3) C:: <projects/opencv Python/opencv_ contrib\modules\xfeatures2d\src\sift. cpp:1207 : error: (- 213: the function/feature is not implemented) this algorithm is patented and is excluded in this configuration; Set OPENCV_ ENABLE_ Nonfree cmake option and rebuild the library in function ‘CV:: xfeatures2d:: sift:: create’
it can be solved by backing the opencv version to 3.4.2, unloading the previous package ( PIP install opencv Python ), and then
PIP install opencv python = = 3.4.2.16
PIP install opencv contrib python = = 3.4.2.16
note that the above two commands = = no spaces are left and right

Error again:

‘module’ object has no attribute ‘xfeatures2d’

Reason: opencv integrates sift and other algorithms into xfeatures 2D set

siftDetector=cv2.SIFT()

Changed to

siftDetector= cv2.xfeatures2d.SIFT_create()

then report another error:

TypeError: Required argument ‘outImage’ (pos 3) not found

im=cv2.drawKeypoints(img_RGB,kp,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
change to im=cv2.drawKeypoints(img_RGB,kp,img,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

SURF:

import cv2

img = cv2.imread(‘cat.jpg’)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

surf = cv2.xfeatures2d.SURF_create()
kp = surf.detect(gray, None)

img = cv2.drawKeypoints(gray, kp, img)

cv2.imshow(“img”, img)

k = cv2.waitKey(0)
if k & 0xff == 27:
cv2.destroyAllWindows()

CentOS7.5 Install Python3.7 error: configure: error: no acceptable C compiler found in $PATH

1. Problem analysis

There is such an error message: configure: error: no acceptable C compiler found in $path that is: configuration error, no acceptable C compiler found in $path

2. Solutions

To install the C compiler GCC (GNU compiler suite): 1

yum -y install gcc

3. Expansion

GCC that is: GNU compiler collection includes the front ends of C, C + +, Objective-C, FORTRAN, Java, ADA and go languages, as well as the libraries of these languages (such as libstdc + +, libgcj ) GCC is a compiler specially written for GNU operating system

Python solves the problem of NameError: name ‘reload’ is not defined

Encountered this problem, for Python 2.X:

1 import sys
2 reload(sys)
3 sys.setdefaultencoding( " utf-8 " )

For Python 3.3 and below:
1 import imp
2 imp.reload(sys)

requires attention:
1. There is a big difference between Python 3 and Python 2. The Python 3 system uses utf- 8 encoding by default .
2. So, for the case of using Python 3, the code of sys.setdefaultencoding( ” utf-8 ” ) is not needed.
3. The most important thing is that there is no setdefaultencoding() function in Python 3 sys library.

For Python 3.4 and above:
1 import importlib
2 importlib.reload(sys)

Python 2.7 and 3.4 requests Error: No module named ‘zlib’

Error reporting

The requests module of Python is installed, and an error is reported during use, as follows
is displayed

[root@payun~]#echo$PYTHONPATH

[root@payun~]#
[root@payun~]#python27
Python2.7.10(default,Oct82015,15:46:46)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
File"/usr/local/python27/lib/python2.7/site-packages/requests/__init__.py",line58,in<module>
from.importutils
File"/usr/local/python27/lib/python2.7/site-packages/requests/utils.py",line26,in<module>
from.compatimportparse_http_listas_parse_list_header
File"/usr/local/python27/lib/python2.7/site-packages/requests/compat.py",line7,in<module>
from.packagesimportchardet
File"/usr/local/python27/lib/python2.7/site-packages/requests/packages/__init__.py",line29,in<module>
importurllib3
ImportError:Nomodulenamedurllib3
>>>exit()
[root@payun~]#


[root@payun~]#python34
Python3.4.3(default,Oct82015,15:22:41)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
Traceback(mostrecentcalllast):
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/__init__.py",line27,in<module>
from.importurllib3
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/__init__.py",line10,in<module>
from.connectionpoolimport(
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py",line41,in<module>
from.responseimportHTTPResponse
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/response.py",line2,in<module>
importzlib
ImportError:Nomodulenamed'zlib'

Duringhandlingoftheaboveexception,anotherexceptionoccurred:

Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
File"/usr/local/python34/lib/python3.4/site-packages/requests/__init__.py",line58,in<module>
from.importutils
File"/usr/local/python34/lib/python3.4/site-packages/requests/utils.py",line26,in<module>
from.compatimportparse_http_listas_parse_list_header
File"/usr/local/python34/lib/python3.4/site-packages/requests/compat.py",line7,in<module>
from.packagesimportchardet
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/__init__.py",line29,in<module>
importurllib3
ImportError:Nomodulenamed'urllib3'
>>>

Python 2.7.10 solution

yum-yinstallzlib-developenssl-devel
cd/wls/softwares/Python-2.7.10
./configure--prefix=/usr/local/python27
make
makeinstall

verification

Python2.7.10(default,Oct82015,17:29:37)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
>>>r=requests.get('https://10.25.7.2')
Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
File"/usr/local/python27/lib/python2.7/site-packages/requests/api.py",line69,inget
returnrequest('get',url,params=params,**kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/api.py",line50,inrequest
response=session.request(method=method,url=url,**kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/sessions.py",line471,inrequest
resp=self.send(prep,**send_kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/sessions.py",line579,insend
r=adapter.send(request,**kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/adapters.py",line430,insend
raiseSSLError(e,request=request)
requests.exceptions.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]certificateverifyfailed(_ssl.c:590)
>>>
>>>r=requests.get('https://10.25.7.2',verify=False)
/usr/local/python27/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:789:InsecureRequestWarning:UnverifiedHTTPSrequestisbeingmade.Addingcertificateverificationisstronglyadvised.See:https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
>>>requests.packages.urllib3.disable_warnings()
>>>r=requests.get('https://10.25.7.2',verify=False)
>>>r.status_code
200
>>>

Python 3.4.3 solution

yum-yinstallzlib-developenssl-devel
cd/wls/softwares/Python-3.4.3
./configure--prefix=/usr/local/python34
make
makeinstall

verification

Python3.4.3(default,Oct82015,17:58:21)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
>>>r=requests.get('https://10.25.7.2',verify=False)
/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py:789:InsecureRequestWarning:UnverifiedHTTPSrequestisbeingmade.Addingcertificateverificationisstronglyadvised.See:https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
>>>requests.packages.urllib3.disable_warnings()
>>>r=requests.get('https://10.25.7.2',verify=False)
>>>r.status_code
200
>>>

 

Python ImportError: No module named win32com.client [How to Solve]

Error in Python: importerror: no module named win32com.client

[questions]

[solved] processing operation in Python chart in Excel

Use the code:

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Function:
[Solved] Handling charts in Excel in Python (Chart, Graph)

【已解决】Python中处理操作Excel中的图表(Chart,Graph)
Author: Crifan Li Version: 2012-12-25 Contact: admin at crifan dot com """ from win32com.client import Dispatch; def excelChart(): ex = Dispatch("Excel.Application"); print "ex=",ex; if __name__ == "__main__": excelChart();

The result runs with the error.

D:\tmp\tmp_dev_root\python\excel_chart>excel_chart.py

Traceback (most recent call last):

File “D:\tmp\tmp_dev_root\python\excel_chart\excel_chart.py”, line 13, in <module>

from win32com.client import Dispatch;

ImportError: No module named win32com.client

[Solution Process

1. Reference.

http://sourceforge.net/projects/pywin32/

Find

http://sourceforge.net/projects/pywin32/files/pywin32/

in the latest

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

Then go and download the corresponding version.

Here I have Win7 64-bit + Python 2.7.3

So it is.

pywin32-218.win-amd64-py2.7.exe

2. After downloading, get pywin32-218.win-amd64-py2.7.exe and go to install: pywin32-218.win-amd64-py2.7.exe.

3. After installation, go try the code again and it will be normal:.

D:\tmp\tmp_dev_root\python\excel_chart>excel_chart.py

ex= Microsoft Excel

[Summary]

Win32com.client corresponds to the library Pywin32, which is installed and ready to use.