To you who develop Python under Windows & proxy

The first thing to say is that if you have a Mac or Linux, Python should be developed with them.

Python on Windows can be quite a hassle. However, for those who have no choice but to use my PC, or Windows, here are some things to keep in mind when running Python under Windows and a proxy that also causes a stumbling block.

Python installation

Don't hesitate to download this from the Download page ... but instead, I recommend downloading it here.

Miniconda

Miniconda is a light version of Anaconda, which is a collection of math processing libraries in Python.

The biggest reason to include Miniconda instead of the original Python is the conda command. Pip, a package installation tool in Python, takes the form of dropping the source and compiling it in its own environment. However, with this method, a C language compilation environment such as gcc (sometimes Fortran) is required on the client side, and Windows does not have such a standard installation on Linux and Mac, so I get an error and cry. You will end up seeing it.

conda will drop the compiled binary so you can be free from this error. So, if you do it on Windows, we recommend installing Miniconda. Inserting conda does not mean that virtualenv cannot be used, so you can use it properly as needed.

The procedure for building a virtual environment when using conda is as follows.

#The virtual environment of conda`<miniconda home>/envs`Created in(If no path is specified)
#Note that if you do not include pip when creating the virtual environment, pip will be installed globally even if the virtual environment is enabled.
conda -n myenv numpy scipy pip 
activate myenv 
conda install <package>
pip install <package>

To use virtualenv as usual, do the following.

#If virtualenv is not installed, install it with pip install.
virtualenv venv

#If you use Git shell, source venv/Scripts/Can be activated
venv/Scripts/activate.bat
pip install <package>

When using virtualenv, you will fight compilation errors head-on as described above. The basic strategy at this time is to first check Unofficial Windows Binaries for Python Extension Packages when an error occurs in pip, and then check the exe there. It is a tactic of using. The exes listed here can be installed with ʻeasy_install`, and if the virtual environment is enabled, it will only enter the virtual environment properly.

install easy_install

Download ʻez_setup.py` from here and perform the installation work.

If that doesn't work, see below.

Proxy considerations

Make sure the powershell used to download the file considers the proxy. Methods presented here

Run in Git shell

Since some Linux commands can be used in Git shell, comment out the judgment of the Windows environment and execute ʻez_setup.py`. I think this will work better in the future, so I think it's a good idea to have "install Git and type commands from the Git shell" as one measure.

Edit as follows (always set to False).

def has_powershell():
	"""
    if platform.system() != 'Windows':
        return False
    cmd = ['powershell', '-Command', 'echo test']
    devnull = open(os.path.devnull, 'wb')
    try:
        try:
            subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
        except Exception:
            return False
    finally:
        devnull.close()
    return True
	"""
	return False

I think either of these will pass.

Installation of development environment

For Eclipse as the standard, download Eclipse and install PyDev for Python. For IDEA, PyCharm is available. However, in the case of the community version, there is no App Engine linkage function, so be careful (it doesn't feel like it was there, so you can use the environment you like or already have). However, you will probably end up with Visual Studio for compiling Visual C ++ at some point, so you can even go with Visual Studio from the beginning. It seems that the compiler on the Visual Studio side is used when compiling the package source, and maybe it is possible to put a compilation library such as numpy without installing MinGW (at least numpy is included ... but I already have MinGW and I'm not sure because I had a solid msys installed). Complementation is also quite excellent, so if you have to do it on Windows, I think it is possible to reopen and go with this.

You should check the Python coding style guidelines (PEP8) during development. In case of Eclipse Settings> PyDev> CodeAnalysis> pep8.py, in case of Visual Studio It will be molded in Edit> Document format instead of checking. Settings such as spaces can be done in Tools> Options> Text Editor> Python. The format is arbitrary, so the force is loose. In the case of IDEA, it is included by default, and the check is also neat.

C compiler preparation

If neither conda nor Unofficial is supported, you will have to compile it yourself.

First, prepare a compiler (MinGW). The installer is from here, but this installer is a method to get files from the Web, and it will be NG if it is under the authentication proxy (as of 2014) ...).

Therefore, download and extract all the files in Files To Get at here. binutils gets bin, gcc-core gets both bin and dll, otherwise dll. Since it is compressed twice as tar.lzma, the environment is created by decompressing all files twice and integrating the decompressed files. Astonishingly incredible hassle, but this is the reality.

After that, you can pass the path of the environment variable to the expanded folder (MinGW etc.).

When specifying the compiler to be used in the virtual environment, for example, if the folder created by virtualenv is venv, it is possible by editing the file distutils.cfg in venv / Lib / distutils.

distutils.cfg


[build]
compiler=mingw32

VC ++ compiler preparation

What to do if you encounter a so-called ʻerror: Unable to find vcvarsall.bat` error. In short, it says there is no VC ++ compiler. It is customary to install the Windows SDK or Visual Studio to set up the environment, but it seems that this has happened recently, so this alone may be possible.

Microsoft Visual C++ Compiler for Python 2.7 (Why not for Python3 ??)

It's customary to have the same compiled version of Python (see here), but it's better to have the latest version installed. I think it's good (for security).

Select "Windows Desktop" to install Visual Studio Express. Be aware that installing another version will be a hassle twice. However, in the future, it will be integrated into the Visual Studio Community, so I think it will not be necessary to choose. The installation is heavy and makes me laugh (as of 2014), but it's a pretty good development environment, so let's put it in here. You can do it with the Windows SDK, but this is quite annoying. If it takes the same amount of time, it's easier to wait for the installation. In addition, since there is a possibility that there will be a version difference between the VC ++ compiler used when compiling Python and the latest version, here % 81% A7-error-unable-to-find-vcvarsall-bat-% E3% 81% 8C% E5% 87% BA% E3% 81% 9F% E5% A0% B4% E5% 90% 88% E3% Set the registry referring to 80% 82 /).

Other tips

About Pit

In Python (but not limited to python), you might use Pit to manage information you don't want to commit, such as passwords. To use this Pit, it is necessary to set the path to the editor's executable file in the environment variable EDITOR, so set it.

Even if you set the editor, it may continue to say No Changes. In that case, edit default.yaml directly in the .pit folder that can be directly under C: \ Users \ user name. As an example, it looks like the following.

"web-site-password":
  "username": 'xxxxx'
  "password": 'xxxxx'

This is OK.

When using App Engine

There is basically no problem with Windows, but when using a proxy, it falls like the following. This is the same pattern on Mac.

Traceback (most recent call last):
  File "C:\environment\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1547, in __call__
    return response(environ, start_response)
・ ・ ・

To avoid this, it is necessary to set App Engine not to start the proxy. Specifically, comment out ʻopener.add_handler (fancy_urllib.FancyProxyHandler ())in... \ Google \ google_appengine \ google \ appengine \ tools`.

appengine_rpc.py


    opener = urllib2.OpenerDirector()
    # opener.add_handler(fancy_urllib.FancyProxyHandler())
    opener.add_handler(urllib2.UnknownHandler())

However, note that if you do this, the external API will not be able to hit. Also, this gets in the way when deploying, so you need to revert this comment when using ʻappcfg.py`.

For details, refer to here. I have been suffering for these two days, so I am in hell.

Recommended Posts

To you who develop Python under Windows & proxy
How to install Python [Windows]
Python environment construction under Windows7 environment
How to develop in Python
Nice to meet you with python
python memo pip under proxy, easy_install
docker and PyCharm under proxy on windows
[Kivy] How to install Kivy on Windows [Python]
Put MicroPython on Windows to run ESP32 on Python
[Python] Memo to translate Matplotlib into Japanese [Windows]
Develop Windows apps with Python 3 + Tkinter (exe file)
Steps to develop a web application in Python
How to use pip3 under proxy environment Note
[Python] How to install OpenCV on Anaconda [Windows]
Updated to Python 2.7.9
What to do if the Microsoft Store opens even if you run python on Windows
Python on Windows
python windows environment
Python installation (Windows)
"Backport" to python 2
How to embed mod_wsgi into Apache on Python Windows
(Python) Try to develop a web application using Django
When you want to play a game via Proxy
Introducing WSL (Ubuntu 18.04) to WIndows10 ~ Proxy environment second part ~
Site notes to help you use NetworkX with Python
Use AWS SDK for Python (boto) under Proxy environment
Tips to look at before you start writing Python
For those who can't install Python on Windows XP
What to do when you can't bind CaboCha to Python
A learning roadmap that allows you to develop and publish services from scratch with Python