Windos python2.7 Installation Pymssql Solution

Source: Internet
Author: User

Recently learning Python, to install pymssql this piece encountered a lot of problems.

First: How to install the Python module is also the main problem.

It is understandable that you can install a module that is responsible for installing the module before you install other Python modules.

The following simple installation method:

First step: Download ez_setup.py website: https://pypi.python.org/pypi/setuptools

Specific methods See: http://jingyan.baidu.com/article/fb48e8be52f3166e622e1400.html

Everyone is pip more useful then the PIP is also installed.

The first step is based on the installation of ez_setup.py, we can use Easy_install PackageName this.

PIP is then installed by Easy_install Pip (run under the command line)

The installation package can be installed later via PIP install PackageName.

However, when you use Pip install Pysmsql for python2.7, the prompt installation is complete.

When importing import pymssql in the Python interactive environment, the error is as follows: Importerror:dll load failed:???????????? 顣

This time can only be a re-think.

Please download EXE installation file directly: File Address: http://download.csdn.net/detail/goodge/9499322

After download, directly double-click Install ...

The following is a database operation using the PYSMSQL connection database:

Simple example:

Import pymssql
Con=pymssql.connect (host= ' 127.0.0.1 ', user= ' sa ', password= ', database= ' dbname ')
Cur=con.cursor ()

Cur.execute (' Select COUNT (*) from bokewu_table ')

Print Cur.fetchall ()
Cur.close ()
Con.close ()

See (http://blog.sina.com.cn/s/blog_56146dc501009hg2.html)

My database connection case:

conn = Pymssql.connect (host= ' localhost:1433 ', user= ' test ', password= ' test123456 ', database= ' test ')
#本地数据库使用host = '. ' can also
cursor = Conn.cursor ()

Print Cur.fetchall () #取出上面读出来的所有数据

    

-------------------------Gorgeous split-line------------------------------------------------------------------------------------

Python module Installation method (from: http://blog.163.com/yang_jianli/blog/static/161990006201162152724339/)


One, Method 1: Single File module
Copy the file directly to the $python _dir/lib

Second, Method 2: Multi-file module, with setup.py

Download the module package, unzip it, go to the module folder, execute:
Python setup.py Install

Third, Method 3:easy_install way

Download ez_setup.py First, run Python ez_setup to install the Easy_install tool, and then you can install the package using Easy_install.
Easy_install PackageName
Easy_install package. Egg

Four, method 4:pip way

Install the pip tool First: Easy_install pip (pip can be installed by Easy_install and also loaded into the Scripts folder. )

Install: Pip Install PackageName

Update: Pip install-u packagename

Removal: Pip Uninstall PackageName

Search: Pip Search PackageName

Help: Pip helps

--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------

note: Although Python modules can be copied and installed, it is generally recommended to make an installation package, which is to write a setup.py file to install.
setup.py file is used as follows:
% python setup.py build      #编译
% python setup.py install            #制作分发包
% python setup.py bdist_wininst    #制作windows下的分发包
% python setup.py bdist_rpm

Preparation of setup.py files
The main implementation of a setup function in setup.py, most of which is descriptive, the most important is the packages parameter, lists all the package, you can use their own find_packages to dynamically obtain the package. So the setup.py file is actually very simple to write.
A simple example:
setup.py file:

 From setuptools Import setup, find_packages
Setup (
      name = "MyTest",
      Version = "0.10",
      Description = "My Test module",
      author = "Robin Hood",
      url = "Http://www.csdn.net",
      license = "LGPL",
      packages = Find_packages (),
      scripts = ["scripts/test.py"],
       )

mytest.py

Import Sys
Def get ():
return sys.path

scripts/test.py

Import OS
Print Os.environ.keys ()

The scripts in setup indicates that the file is placed in the Python scripts directory and can be used directly. OK, a simple installation succeeds, you can run the commands listed to build the installation package, or install the Python package. Native test succeeded (WIN32-PYTHON25)!


Note: Setuptools Tool installation Method

(method i). Install with ez_setup.pySetuptools

go to https://pypi.python.org/pypi/setuptools download ez_setup.py
This is setuptools proud of a way of installation, only need a 8K as a script ez_setup.py, you can automatically install for the user including Setuptools itself, many Python packages. In this way, users only need to download ez_setup. Py and run, you can automatically download and install the appropriate Setuptools egg file for the user's current Python version (of course, users need Python 2.3. More than 5 versions, 64-bit operating system users will need python more than 2.4 version). In addition, the script installs the executable Easy_install script to a location where the user's operating system Python executable scripts should be installed (for example, Windows users are installed in the Scripts directory in the Python installation directory). For more detailed instructions and precautions on this installation method, please refer to their official instructions (see extended reading). The simple installation command is as follows: Wget-q Ez_setup. PY (see extended reading) after installation, it is best to ensure that

(method Two). Install Setuptools using the full installation package

Of course, users can also install them directly using the Setuptools release version. This is also a handy way for users who use Windows, and many of the official package management repositories for Linux distributions contain a version of Setuptools. For example, if you're using Ubuntu the same way as I do, installing setuptools is simply doing the following:
# Apt-get Install Python-setuptools

Install easy_install package-name, such as Easy_install PylabModule Unloading easy_install-m package-name, such as Easy_install-m Pylabeasy_install-m Package Name, you can uninstall the package, but also manually delete the legacy files after uninstallation.

Setuptools It can automatically install the module, just need you to give it a module name can be, and automatically help you solve the module dependency problem. In general, the modules installed with Setuptools will automatically be placed in a directory with a suffix of. Egg.

in Windows, easy_install This command in the Python installation directory under the scripts, so you need to add scripts to the environment variable path, so it is more convenient to use, Linux does not need to pay attention to this problem.

Windos python2.7 Installation Pymssql Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.