Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't figure out how to build a python that uses the .SO file #65

Closed
mark0978 opened this issue Oct 11, 2013 · 11 comments
Closed

Can't figure out how to build a python that uses the .SO file #65

mark0978 opened this issue Oct 11, 2013 · 11 comments

Comments

@mark0978
Copy link

All of this is with 2.7.5

We are trying to build on Centos6, the python pyenv builds produces a libpython.a, but not a libpython.so

We have an importable module we build against python using libboostpython. These need to link against a libpython.so

We also need to run under mod_wsgi in apache, so the shims situation is problemmatic. I've set PYTHONHOME to point at the pyenv version of python, but it still goes after 2.6 modules on the main system.

Maybe I'm wrong here, but I am thinking if I could build python to use the .so library, and then link my extension against it, it would work (it does on Debian where I'm NOT using pyenv because I have 2.7 as the base python)

How do you get pyenv to build a python that is based on libpython.so instead of libpython.a?

python is 6MB on Centos, vs 2MB on Debian, I'm assuming that is because libpython.so makes up the other 4MB.

@yyuu
Copy link
Contributor

yyuu commented Oct 11, 2013

At first, I don't recommend you to use pyenv always, especially for server applications. The pyenv is mainly designed for development use. If you have problem of pyenv with mod_wsgi, I would recommend you to rebuild dedicated CPython for mod_wsgi without using pyenv.

Second, if you want to create shared library of CPython, you might need to specify --enable-shared as an option of ./configure. Please try to rebuild with env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 2.7.5 to enable shared library. If you have finished building CPython with --enable-shared, you might need to declare proper LD_LIBRARY_PATH to load built shared library.

Third, the binary size issue between CentOS and Debian sounds strange for me. I'd like to check the difference between them.

@tarruda
Copy link

tarruda commented Oct 22, 2013

@yyuu perhaps pyenv could set LD_LIBRARY_PATH from the shim when invoking a python binary compiled with '--enable-shared'? Setting LD_LIBRARY_PATH explicitly on bashrc has the problem that system applications(ubuntu apps for example) that depend on libpython will be dynamically linked to the wrong file.

It would be nice to build some apps like vim or weechat against a libpython compiled with pyenv

  • Update: by default pyenv fails to build python with '--enable-shared' since the installation process will invoke the installed python to complete the installation of pip/setuptools set so pyenv should also set LD_LIBRARY_PATH during installation.

@mark0978
Copy link
Author

Here is how we deal with it

env PYTHON_CONFIGURE_OPTS="--enable-shared" LD_LIBRARY_PATH=~/.pyenv/versions/2.7.5/lib/ pyenv install -k 2.7.5

Considering the # of webapps that need mod_wsgi, this really needs to be an option, or maybe even the default.

@yyuu
Copy link
Contributor

yyuu commented Oct 23, 2013

The LD_LIBRRY_PATH is for GNU/Linux. Darwin uses DYLD_LIBRARY_PATH as the library search path. We must treat most of platforms properly.

@tarruda
Copy link

tarruda commented Oct 23, 2013

I found a better way to do it that doesn't depend on pyenv setting LD_LIBRARY_PATH:

PYTHON_CONFIGURE_OPTS='--enable-shared' LDFLAGS="-Wl,-rpath=$HOME/.pyenv/versions/2.7.5/lib" pyenv install 2.7.5

This will add the the python lib directory to the rpath of the python executable. The rpath is searched before LD_LIBRARY_PATH and ld.conf.so, so there's no way pyenv's installed python will try to load the system's libpython which may be of a different version.

@yyuu
Copy link
Contributor

yyuu commented Dec 20, 2013

I pushed 43212f6 which will set rpath if --enable-shared was given in PYTHON_CONFIGURE_OPTS. With this fix, just passing --enable-shared will resolve the issue.

$ env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.5

@yyuu yyuu closed this as completed Dec 20, 2013
@mark0978
Copy link
Author

Thanks, we just started messing with rpath for some of our SO's yesterday.

@seanfisk
Copy link

We just got this working with rpath too! Thanks for being on top of this, @yyuu!

yyuu pushed a commit to yyuu/homebrew that referenced this issue Jan 10, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.
yyuu pushed a commit to yyuu/homebrew that referenced this issue Jan 10, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.
yyuu pushed a commit to yyuu/homebrew that referenced this issue Jan 10, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.
yyuu pushed a commit to yyuu/homebrew that referenced this issue Jan 10, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.
yyuu pushed a commit to yyuu/homebrew that referenced this issue Jan 23, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.
yyuu pushed a commit to yyuu/homebrew that referenced this issue Jan 23, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.
MikeMcQuaid pushed a commit to Homebrew/legacy-homebrew that referenced this issue Jan 24, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.

Closes #25783.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
ehershey pushed a commit to ehershey/homebrew that referenced this issue Apr 4, 2014
Changes:

* pyenv: Reliably detect parent shell in `pyenv init` (pyenv/pyenv#93)
* pyenv: Import recent changes from rbenv 0.4.0
* pyenv: Import `bats` tests from rbenv 0.4.0
* python-build: Add new CPython releases candidates; 3.4.0b2
* python-build: Add ruby-build style patching feature (pyenv/pyenv#91)
* python-build: Set `RPATH` if `--enable-shared` was given
  (pyenv/pyenv#65, pyenv/pyenv#66, pyenv/pyenv#82)
* python-build: Update default setuptools version (2.0 -> 2.1)
* python-build: Update default pip version (1.4.1 -> 1.5)
* python-build: Activate friendly CPython during build if the one is not
  activated
* python-build: Fix broken install.sh
* python-build: Import recent changes from ruby-build v20131225.1
* python-build: Fix build error of CPython 2.x on the platform where the
  `gcc` is llvm-gcc.
* version-ext-compat: Removed from default plugin. Please use
  [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext)
  instead.

Closes Homebrew#25783.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
@blueyed
Copy link
Contributor

blueyed commented Aug 12, 2014

For reference: when building Vim make sure to only enable either python2 or python3, otherwise Vim's dynamic loading of python will cause Vim to pick up the system's python.
(Or you would have to also add rpath information to Vim or use LD_LIBRARY_PATH).

@pingsoli
Copy link

pingsoli commented Jun 5, 2018

I use fish shell, what should I do ?

env PYTHON_CONFIGURE_OPTS="--enable-shared" LD_LIBRARY_PATH=~/.pyenv/versions/2.7.5/lib/ pyenv install -k 2.7.5 works in bash shell, but not in fish shell.

@pingsoli
Copy link

pingsoli commented Jun 5, 2018

I solved it.

eval (env YTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.5) works in fish shell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants