How do I point easy_install to vcvarsall.bat? - python

I already have MSVC++ 2010 Express installed, and my vcvarsall.bat file is at C:\Program Files\Microsoft Visual Studio 10.0\VC, which is in my system PATH. When I run easy_install, it can't find vcvarsall.bat.
Is there something I need to set in my distutils.cfg file to point it to my MSVC++ installation?
G:\>easy_install hg-git
install_dir C:\Python26\Lib\site-packages\
Searching for hg-git
Best match: hg-git 0.2.6
Processing hg_git-0.2.6-py2.6.egg
hg-git 0.2.6 is already the active version in easy-install.pth
Using c:\python26\lib\site-packages\hg_git-0.2.6-py2.6.egg
Processing dependencies for hg-git
Searching for dulwich>=0.6.0
Reading http://pypi.python.org/simple/dulwich/
Reading http://samba.org/~jelmer/dulwich
Reading http://launchpad.net/dulwich
Best match: dulwich 0.7.1
Downloading http://www.samba.org/~jelmer/dulwich/dulwich-0.7.1.tar.gz
Processing dulwich-0.7.1.tar.gz
Running dulwich-0.7.1\setup.py -q bdist_egg --dist-dir c:\docume~1\mlin\locals~1
\temp\easy_install-fhraep\dulwich-0.7.1\egg-dist-tmp-qozily
error: Setup script exited with error: Unable to find vcvarsall.bat

I'd still like to know where to set that reference to vsvarsall.bat...
Well, as martineau wrote you have to have either Visual Studio 2008 or Visual C++ Express installed. Having said that I understand you would like to know where Python looks for this batch file. You can see this by looking at definition of find_vcvarsall function in distutils/msvc9compiler.py standard module. Python checks in turn if any of folders saved in the registry under keys
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VCExpress\9.0\Setup\VC\ProductDir
(for 64bit Windows) or
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
HKEY_LOCAL_MACHINE\Software\Microsoft\VCExpress\9.0\Setup\VC\ProductDir
(for 32bit Windows) exists and if so it treats such folder as the one containing vcvarsall.bat file. If none of these folders exists Python checks if there's environment variable VS90COMNTOOLS. If this variable exits Python treats folder two levels above value of this variable as the folder containing vcvarsall.bat file.
See also my other answer which explains why you can't use MSVC++ 2010 to build extensions for Python 2.6
EDIT:
The VC++ 2008 files are now packaged in an installer from MS which can be downloaded here. Once installed vcvarsall.bat will be in C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

Met same problem on python 3.9.12 (anaconda),I install Visual C++ for Python at
C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
and find the msvc9compiler.py at
C:\Users\UserName\anaconda3\Lib\distutils
showed
VS_BASE = r"Software\Microsoft\VisualStudio%0.1f"
how to point the vcvarsall.bat to python ?
(I added the system PATH but not working at all.)
C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
May you please point out how to add registry for the value?
I did't find HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
in my PC.

Related

How to install SIP & PyQT on windows 7

I'm a newbie to Python environment & really struggling to install SIP & PyQt on my Win 7 machine.
This is what I've done so far,
I've downloaded SIP-4.16.9 and extracted files from the zip folder
The extracted folder is then copied to C:\Python34\Lib
Launched a command prompt(cmd) and changed path to C:\Python34\Lib
Then when I entered python configure.py at C:\Python34\Lib and I get the response as below
At this stage I'm not sure whether it's been installed successfully, to verify I looked for SIP.h at C:\Python34\Include(according to above response - in red), but I cant find any such header file, so I assume the installation hasn't been successful.
Could any one help me, what am I missing here?
Additional System Info:
Windows 7 64 Bit
Python 3.4
Environment Variable (Path : C:\Python34;C:\Python34\Lib;C:\Python34\Lib\site-packages)
Note: There are several questions posted before, but none of them helped so far, I'm sure I must be missing something silly.
Thanks for your time.
For next users who need to build sip (or pyqt) in windows using sources
ALL these instructions are for 32-bits, it will work even if you have a 64-bit system.
For Qt 5.9.x :
Since Qt 5.9, there is only one version of Qt downloadable for Windows that includes the pre-built components for MSVC201x and MinGW.
The instructions follow the same steps as for Qt 5.8
Since Microsoft Visual Studio 2015 Community Edition is not available to download anymore, next users should use Microsoft Visual Studio 2017 Community Edition with Qt 5.9 and follow the same instructions below.
Microsoft Visual Studio 2017 Community Edition (32-bits)
https://www.visualstudio.com/downloads/
Qt 5.9.x
http://download.qt.io/archive/qt/
When Installing Qt, make sure to select the correct pre-built components you have (for e.g Microsoft Visual Studio 2017)
For Qt 5.8 and earlier :
Downloads
Download Python 3.6.x (32-bits) any version will do it :
https://www.python.org/downloads/
(if you also have python 2.7, make sure to use verions 3 of python)
Download sources for sip and PyQt5: Under "Source Packages", download the "Windows Source"
https://www.riverbankcomputing.com/software/sip/download
https://www.riverbankcomputing.com/software/pyqt/download5
Microsoft Visual Studio 2015 Community Edition (32-bits)
https://www.microsoft.com/en-us/download/details.aspx?id=48146
Qt 5.8.0 for Windows 32-bit (VS 2015, 1.0 GB)
http://download.qt.io/archive/qt/
Qt download link must match the Visual Studio (VS) version installed (here VS 2015) and the PyQt5 version you need to install
For example:
PyQt5.8.2
Qt5.8.0 (Link for VS 2015)
Microsoft Visual Studio 2015
Compilation
Open a terminal and stay on it.
It is important you stay on the same terminal (cmd.exe) during the whole process so you don't have to source your environment twice.
Let's create an environment to compile PyQt and SIP (in order to compile PyQt, you need first to compile sip)
Create a folder "compilation" in your Desktop for example:
Extract the content of your sip archive in this forlder
Extract the content of your PyQt5 archive in this forlder
You should have now :
.
├── compilation
| ├── sip-4.19.2/
| └── PyQt5_gpl-5.8.2/
Make sure you are using Python 3.x:
1 - SIP
Go to sip-4.19.2 folder and run :
python configure.py
At this step, you did not install sip, you only configured it (basically its installation dir, etc...)
VERY IMPORTANT STEP: source your environment variables by running in the terminal :
Keep the double quotes, windows does not like spaces ...
"C:\Qt\Qt5.8.0\5.8\msvc2015\bin\qtenv2.bat"
After running this command, it automatically change your current directory, stay on the terminal and re-go to your sip-4.19.2 directory and run:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
In windows, "make" is substituted by "nmake" !
Then (always in the same terminal) you run :
nmake
[...]
nmake install
This will create a sip.exe in your Python dir, for me it is C:\Python36, it may elsewhere, depending on where you installed Python.
2 - PyQt5
The steps are almost the same as sip but it will take more time.
Go to PyQt5_gpl-5.8.2 folder and run :
python configure.py --disable QtNfc --confirm-license
Note that this command disable QtNfs because of a compilation problem I could not resolve.. and automatically accepts the license.
Then, run (the compilation will take a while) :
nmake
nmake install
Hope this helps.
There's a ONE SHOT solution to all your installation problems on Windows. Go to this website. http://www.lfd.uci.edu/~gohlke/pythonlibs/. Navigate to the library you want and download the .whl file for your python version and your computer (32 or 64 bit.) Then run pip install YourWhlFileName.whl, and you're done! (CAUTION: MAKE SURE NOT TO CHANGE THE NAME OF THE WHL FILE OR IT WON'T WORK.)
This is for all that want to build PyQt4 with latest Qt4 and Python 3.4.x.
Download Visual Studio 2010 from here:
http://download.cnet.com/Microsoft-Visual-Studio-2010-Ultimate/3000-2383_4-75450998.html
then install it.
Download SIP source code (in my case version 4.19.5) from here:
https://www.riverbankcomputing.com/software/sip/download
Download PyQt4 source code (in my case version 4.12.1) from here:
https://www.riverbankcomputing.com/software/pyqt/download
Extract SIP and PyQt .zip archive in \Users\your_username\Desktop\compilation\
Download latest Qt 4.x (vs2010 version) installer from here:
http://download.qt.io/archive/qt/
Install Qt (in my case qt-opensource-windows-x86-vs2010-4.8.6.exe).
Open a command prompt (use this one for all the process) and execute these commands:
cd \Users\<your_username>\Desktop\compilation\sip-4.19.5
python configure.py
"C:\Qt\4.8.6\bin\qtvars.bat"
In the output take note of QMAKESPEC value, in my case win32-msvc2010, then use it later on --spec option for PyQt4 configure-ng script.
If the current directory has been changed, execute again:
cd \Users\<your_username>\Desktop\compilation\sip-4.19.5
Now, if you use 64-bit version of Python execute:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
otherwise, if you use 32-bit version of Python execute:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
nmake
nmake install
cd \Users\<your_username>\Desktop\compilation\PyQt4_gpl_win-4.12.1
Now use previous QMAKESPEC value in --spec option:
python configure-ng.py --spec win32-msvc2010
nmake
nmake install
That's all ;-)
NOTE: in some cases, in order to avoid this error
ImportError: DLL load failed: The specified procedure could not be found.
it is necessary to copy .dll files from
C:\Qt\4.8.6\bin
to
C:\Python34\Lib\site-packages\PyQt4

Python on Windows - compiling

Like many before me I don´t succeed in installing a few Python packages (mysql, pycld2, etc.) on Windows. I have a Windows 8 machine, 64-bit, and Python 3.4. At first I got the well-known error "can´t find vcvarsall.bat - install VS C++ 10.0". This I tried to solve by installing MinGW and use that as compiler. This did not work. Then finally I found an installer for this VS C++ 10.0 here http://microsoft-visual-cpp-express.soft32.com/free-download/. This doesn´t work too good either. Now it seems to find the vcvarsall file but instead gives me a couple of new errors
nclude -IC:\Python34\include /Tc_mysql.c /Fobuild\temp.win32-3.4\Release\_mysql.
obj /Zl_mysql.c_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h':
No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\BIN\\cl.exe' failed with exit status 2
And:
pycldmodule.cc
bindings\pycldmodule.cc(16) : fatal error C1083: Cannot open include file: '
strings.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\BIN\\cl.exe' failed with exit status 2
So now it doesn´t find strings.h and config-win.h and I´m too new to these sorts of problems to know what to look for. Anyone knows what I should do?
The thing is that I could just not use Windows and go over to Ubuntu as, for what I´ve understood, works painlessly with python. However, I have to use the win32com package which doesn´t exist on Ubuntu (have I understood that right?).
If I can´t solve these installing hassles on Windows, would a solution be to use a Windows virtual machine for the win32com part and do the rest on a host Ubuntu (or the other way around)? Would there be anyway to communicate between the two in that case? I.e. sending strings or arrays of data.
I have faced the exact same issues for Python 2.7 on 64 bit Windows trying to install pycld2.
Tried many methods like installing VS express 2008, MingW, etc and it just doesnt work.
What saved me is this link:
https://github.com/aboSamoor/polyglot/issues/11
The proposed solution is to download the binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and pip install .whl
The cpXX denotes the version of python. So in my case, I used cp27.
Hope it helps
I would recommend installing Ubuntu (as a Ubuntu user), you can dual-boot. However, that isn't an answer.
MySQLClient (the fork for Python3) is available a precompiled binary from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
Try to find precompiled binaries for simplicity sake. As far as troubleshooting the install goes, I've tried the recommend VC Studio 9.0 on fresh installs and it cannot find stdint.h (which, like yours, suggests it's more than broken).
You could try http://www.activestate.com/activepython/downloads for Windows. I t includes compiled binaries, avoiding the need for a C complier.
I grew frustrated with trying to get python and other packages to compile/play nicely on Windows as well. Switching over to Ubuntu was a breath of fresh air, for sure.
The win32com package is made specifically for Windows hosts, so that could not longer be used, but there are other ways to achieve the same thing in Ubuntu.
Are you trying to target Windows specifically? What are you using win32com for?
Looks like you're missing MySQL dev package. Another StackOverflow question has the details. But if I were you, I'd go the route Alexander Huszagh recommended and get my precompiled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

trouble installing pcapy on windows 7 - cannot open include file: 'pcap.h'

I am trying to install pcapy on a Windows machine. I have already installed WinPcap 4.1.3
I downloaded pcapy 0.10.8 into C:\pcapy-0.10.8
When I try to do the install, the following happens:
C:\pcapy-0.10.8>c:\Python27\python.exe setup.py install
running install
running build
running build_ext
building 'pcapy' extension
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\Bin\amd64\cl.exe /c /nolog o /Ox /MD /W3 /GS- /DNDEBUG -DWIN32=1 -Ic:\devel\oss\wpdpack\Include -Ic:\Python27\include -Ic:\Python27\PC /Tppcapdumper.cc /Fobuild\temp.win-amd64-2.7\Release \pcapdumper.obj
pcapdumper.cc
pcapdumper.cc(12) : fatal error C1083: Cannot open include file: 'pcap.h': No such file or directory
error: command 'cl.exe' failed with exit status 2
I don't know where it's looking for pcap.h. I can confirm that there is no file by that name in the pcapy-0.10.8 directory.
What am I missing? I just now installed WinPcap -- do I need a reboot or something? Thanks!
Edited to add... here is the output from my WinPcap install log:
WinPcap 4.1.0.2980 Installation LOG
-----------------------------------------------------
Debug Information
Operating system detected on registry: 7 - AMD64
True operating system (kernel.dll): 7 - AMD64
npptools.dll present on the system: false
netnm.inf present on the system: false
nmnt.sys present on the system: false
End of log
-----------------------------------------------------
Do the falses there mean that WinPcap did not get installed properly? I was hoping to find pcap.h under my WinPcap directory, but it's not there. I do see where I could add additional include file directories in the setup.py if needed, but I can't find pcap.h anywhere on my machine. Where am I supposed to be getting that from?
C:\pcapy-0.10.8>c:\Python27\python.exe setup.py install
From the text on the CoreLabs site for pcapy, that suggests that you downloaded the source rather than the Win32 binary. Unless you really need to build from source, you will probably find it a LOT easier to just install the binary.
Do the falses there mean that WinPcap did not get installed properly?
No.
I was hoping to find pcap.h
Then, IF you NEED to build from source, you need to install the WinPcap Developer's Pack. WinPcap is just the "run time", sufficient for programs such as Wireshark that have already been built, but not sufficient for software that uses WinPcap and that need to be compiled on your machine - and, apparently, whatever flavor of pcapy you downloaded needs to be built.
(This is similar to the way libpcap is packaged on many Linux distributions - the "libpcap" package just installs the run time, and you need to install a "libpcap-dev" package, or something such as that, to get the header files.)
But if the Windows binary works for you, don't bother with the WinPcap developer's pack.
Building on Josh P's answer (which I used to get most of the way there just now):
download the WinPcap Developer's pack
extract the zip file (e.g. c:\users\foo\Downloads\WpdPack_4_1_2)
build using the --global-option to pass in the header and linker locations
When specifying the library folder for the linker, on Windows 7, I needed to specify the x64 version of the lib, not the (default) x32 version of the lib:
pip install pcapy --global-option="build_ext"
--global-option="-Ic:\users\foo\Downloads\WpdPack_4_1_2\WpdPack\include"
--global-option="-Lc:\users\foo\Downloads\WpdPack_4_1_2\WpdPack\lib\x64"
I was getting the following link errors when using the ...\lib (x32) version of the file:
Creating library build\temp.win-amd64-2.7\Release\pcapy.lib and object build\temp.win-amd64-2.7\Release\pcapy.exp
pcapdumper.obj : error LNK2019: unresolved external symbol pcap_dump_close
referenced in function "void __cdecl pcap_dealloc(struct pcapdumper *)"
(?pcap_dealloc##YAXPEAUpcapdumper###Z)
As Guy Harris explained, it's generally easier to download install a binary. If you do build from source:
Download the WinPcap Developer's Pack.
Use pip's --global-option. setup.py is different, but I think pip is preferred over setup.py anyway.
Here's an example line (substitute in the correct paths for your system; I just referenced them right in the Downloads folder):
pip install ./pcapy-src-dir --global-option=build_ext --global-option="-LC:\path\to\WpdPack_4_1_2\WpdPack\Lib" --global-option="-IC:\path\to\WpdPack_4_1_2\WpdPack\Include
See also this answer.
In the pcapy-0.11.1 the setup.py is smarter, even smarter that what they described on their wiki page: https://github.com/CoreSecurity/pcapy/wiki/Compiling-Pcapy-on-Windows-Guide
The investigation demonstrated that's enough to set environment variable WPDPACK_BASE, so in Windows' case it may look like:
set WPDPACK_BASE=C:\Software\WpdPack
It's even able to detect if you need 32 or 64 bit version of these libraries.
Previous answers didn't help me solve the problem, but helped me digging. So they may be bit outdated.

pyusb 2.7 windows install error

I know similar things have been asked, but none of the solutions work for me/I get different errors. I am trying to install PyUSB on a 64-bit Windows 7 VM, with Python 2.7.
When I run the install from command line, i get error: Unable to find vcvarsall.bat. When I try to run the compiled executable to install, I get an error saying Python 2.7 was not found in the registry.
Any help with this would be greatly appreciated.
If you haven't installed VS 2008, don't.
If you have installed VS 2008 and can't get extensions to compile, I would uninstall VS 2008 and remove the directory for it under program files. The problem is likely to be that the express version doesn't ship with the 64-bit compilers.
To get compiling extension files, install the Python 2.7 compilers for Windows from
http://www.microsoft.com/en-gb/download/details.aspx?id=44266
The instructions say that setuptools 6.0 is needed but I couldn't get it to work even after updating.
Once the compilers are installed, locate the directory containing vcvarsall.bat. For me it was
C:\Users\MY_USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
Open powershell there and run .\vcvarsall.bat amd64
If you see this:
PS C:\Users\MY_USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0> .\vcvarsall.bat amd64
Setting environment for using Microsoft Visual Studio 2008 x64 tools.
All is well.
The next step is bizarre but essential and is explained at the end. Rename the directory 9.0 to VC.
Add the environment variable VS90COMNTOOLS and set the value to be the path of your bin directory, which should now be:
C:\Users\MY_USER_NAME\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\VC\VC\bin
Now it should all work. Go and test it on an extension file:
python setup.py build_ext --inplace
Why the renaming of 9.0 to VC? Go to your python installation directory and find the distutils directory: python_base_dir\Lib\distutils
Open up msvc9compiler.py in your text editor of choice and find line 247.
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
This means that distutils will simply navigate to the environment var you added, go up two levels and then down into the VC file, hoping to find vcvarsall.bat.
You can edit this file as an alternative to renaming 9.0 -> VC but I thought that was "dirtier".
Also note the reason there needs to be no VS 2008 directory is line 242:
if not productdir or not os.path.isdir(productdir):
which ignores old registry entries for VS 2008 if the directory is removed.

Why do I get an error on the last line of installing Pylons 1.0 with easy_install and Python 2.7 in Windows Vista 64?

I tried to install Pylons 1.0 with Python 2.7 using the easy_install command in Windows Vista 64 but got the error:
raise ValueError(str(list(result.keys())))
ValueError: [u'path']
Here is the link to the whole installation process from command prompt
http://pastie.org/1190341
Why do I get this error?
How do I solve it?
Will Pylons work even though I got this error?
From the error:
File "C:\Python27\Lib\distutils\msvc9compiler.py", line 295, in q
uery_vcvarsall
raise ValueError(str(list(result.keys())))
ValueError: [u'path']
distutils looks for a file called vcvarsall.bat. It runs it and gets the include and lib directories that the batch file sets up. The batch file sets up the environment based on what platform you supply to it.
vcvarsall.bat should be in a directory like: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC
Create following directories:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat
in vcvarsamd64.bat
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 /Release
All these above sets up windows tool chain to work with disutils. While you may have 64 bit python, most packages on pypi comes with 32 bit precompiled binaries. disutils needs to use your compiler tool chain for building 64 bit extensions. This is where all this come into picture.
Please look at :
http://blogs.msdn.com/b/vcblog/archive/2007/12/30/using-different-toolsets-for-vc-build.aspx
What vcvarsamd64.bat and other batchfile does is setup up paths for libs, tools etc which can be used by disutils.
[Edit: setenv.cmd not found in v6]
https://serverfault.com/questions/114998/vista-cmd-shell-thinks-its-windows-server-2008-debug
There's a workaround mentioned on pylons discuss list:
simplejson workaround for Pylons 0.9.7 on Windows, Python 2.6
It's a bit old (2008), but since your pasted output shows failure on compiling simplejson, it seems relevant. You might try following the suggestions there to see if it helps.
if you have installed x64 visual studio you can use the cmd tool in the visual studio tools in the start menu. It will set up the environment for you.
It looks like you couldn't build a C extension, something that is often difficult for Windows users. Try to find a Windows kit for Pylons. Or, look for help on installing MinGW so you can build the extensions.
I spent a huge amount of time trying to get the c++ compiler to work with 64 bit Python on 64 bit Windows. It turns out the answer was here.
http://msdn.microsoft.com/en-us/library/ms246588(v=vs.90).aspx
Run the VS 2008 Professional installer again and make sure make sure "X64 Compilers and Tools" is selected in the installer options.

Categories

Resources