3

I'm trying to deploy a Python application on a machine that due to system and organisation requirements can't have gcc installed on it, so I need to create a self-contained installation file for pymssql (normally it requires FreeTDS and gcc gcc-c++).

I've managed to get rid of the FreeTDS requirement by using
export PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1 before installing pymssql, but it still fails on the gcc requirement.

Is there any way to pre-compile pymssql so it can be deployed and installed on a machine with no dependency on neither FreeTDS nor gcc?

0

3 Answers 3

2

I assume you are using the CentOS system Python as it would be difficult to install a different (up-to-date) python without access to gcc.

Setup a VM (e.g. in VirtualBox) with the exact same CentOS version, hosted on a different machine. In that VM install the required gcc, and install virtualenv ( I recommend doing that from source, the one you can install with your package manager is quite often outdated).

On the VM, create a virtual environment e.g. with virtualenv /opt/util/pymssql, this virtual environment will have references to the real python but since you are going to move it to an equivalent CentOS, that is ok.

Activate the environment ( source /opt/util/pymssql/bin/activate ) and use pip to install all the libraries that you need.

When all is installed and working, tar the /opt/util/pymssql and its subdirectories and put it on the "real" CentOS machine in the same location. That should give you working code without a compiler on the "real" machine.

The actual directory (in the example /opt/util/pymssql) for the virtual environment is not important, but you have to use the path that will be used on the "real" machine, some of the files in the virtual env will have the path hardcoded.

2
  • 1
    It sounds to me like you're trying to reinvent the wheel, or in this case RPM packages.
    – jsbillings
    Mar 20, 2016 at 12:37
  • 1
    @jsbillings I have provided RPMs for SuSE distributions and getting that to work is at least a magnitude more effort than creating a one-off virtualenv as described above. But feel free to describe the steps on how to do this based on creating an RPM
    – Anthon
    Mar 20, 2016 at 12:42
1

The proper way to do this is to build your own CentOS package. It looks like there was, at one time, a package for pymssql, but it was abandoned because of lack of maintainers, but you could use the spec file in Fedora's git repo as a starting point:

http://pkgs.fedoraproject.org/cgit/rpms/pymssql.git/tree/pymssql.spec

0

Set up VM with same OS and install needed tools (gcc) as Anthon suggests but instead of creating and zipping virtualenv (which is kind of a hack) build binary wheel and install this wheel in target system.

Related:
How to avoid building C library with my python package?
Build a wheel/egg and all dependencies for a python project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.