-
Notifications
You must be signed in to change notification settings - Fork 75
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
(on 1.3.0): Fatal Python error: Py_Initialize: Unable to get the locale encoding #121
Comments
That error has occurred in Python-side, so it seems not pycall.rb's issue. |
Hi!
On 2020/05/25 04:41, Kenta Murata wrote:
That error has occurred in Python-side, so it seems not pycall.rb's issue.
Please investigate your Python's settings such as environment variables.
Can you please explain your reasoning? If everything works fine with
pycall 1.2.1, and just upgrading to pycall 1.3.0 causes the problem its
hard for me to understand that the error is outside of what pycall does.
Sure, it might have to do with PYTHONPATH or other variables controlling
python, but I was under the impression its pycall's taks to set these up
and invoke python correctly?
Is there something I can check and post here that can throw more light
on the issue?
Regards
Iwan
…--
|
I missed looking at the last line of the description. I'm sorry. I've tried to reproduce this with Python 3.5.9, but I couldn't install Python 3.5.9 in my macOS due to the build error. Please wait some days for constructing the testing environment. By the way, how do you construct your environment? I noticed your libpaths contains the string
If you didn't use the vanilla environment of Python, please tell me how to prepare the environment that is the same as yours. |
Ah, thanks for looking into it - I'd have no idea where to look!
This is on stock ubuntu 16.04, with its stock python 3.5.2 installed
(called python3 on ubuntu 16.04). We also install stock python3-pip and
python3-venv.
The path /var/local/venv/development you see is the path to a venv,
created (assuming /var/local/venv exists) by running:
pyvenv /var/local/venv/development
We also install inside the venv:
pip==20.1.1
setuptools==46.4.0
I have also now installed it on Ubuntu 18.04 with the same results, here
I used:
python3 -m venv /var/local/venv/development
to create the venv
And I used the stock python3, python2-pip, python3-venv of ubuntu 18.04
with the same pip and setuptools as above.
Thanks
Iwan
…On 2020/05/27 00:45, Kenta Murata wrote:
I'm sorry, I missed the last line of the description.
I've tried to reproduce this with Python 3.5.9, but I couldn't install
Python 3.5.9 in my macOS due to the build error. Please wait some days
for constructing the testing environment.
By the way, how do you construct your environment? I noticed your
libpaths contains the string |venv|:
|DEBUG(find_libpython) libpaths: ["/usr/lib",
"/var/local/venv/development/lib", "",
"/var/local/venv/development", "/var/local/venv/development/lib"] |
If you didn't use the vanilla environment of Python, please tell me how
to prepare the environment that is the same as yours.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#121 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARGTN247HKQMROO5SDORNDRTRBCHANCNFSM4NDACSLA>.
--
Reahl, the Python only web framework / www.reahl.org
|
Have same error on Mac OS through venv. Not elegant but using system Python solves this |
I'm having a similar issue on ubuntu 18.04, on a virtualenv, with 1.3.0 and 1.3.1. 1.2.1 works (but complains about
|
@jmarrec Could you please explain the steps for reproducing the same problem you encountered? |
@mrkn Yes sure, thanks for your prompt reply. Install pycall 1.2.1
Require 'sys', it works: (py38)julien@OpenStudio-workflow-gem (python_measure_mod *>)$ irb
2.5.5 :001 > require 'pycall/import'
=> true
2.5.5 :002 > include PyCall::Import
=> Object
2.5.5 :003 > pyimport 'sys'
=> :sys Now uninstall pycall 1.2.1, and install 1.3.1 instead: (py38)julien@OpenStudio-workflow-gem (python_measure_mod *>)$ gem uninstall pycall
Successfully uninstalled pycall-1.2.1
(py38)julien@OpenStudio-workflow-gem (python_measure_mod *>)$ gem install pycall
Fetching pycall-1.3.1.gem
Building native extensions. This could take a while...
Successfully installed pycall-1.3.1
1 gem installed And try again: (py38)julien@OpenStudio-workflow-gem (python_measure_mod *>)$ irb
2.5.5 :001 > require 'pycall/import'
=> true
2.5.5 :002 > include PyCall::Import
=> Object
2.5.5 :003 > pyimport 'sys'
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 769, in <module>
main()
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 746, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 279, in addsitepackages
addsitedir(sitedir, known_paths)
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 202, in addsitedir
addpackage(sitedir, name, known_paths)
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 170, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/home/julien/Virtualenvs/py38/lib/python3.8/site-packages/_virtualenv.py", line 41, in <module>
from importlib.util import find_spec
File "/home/julien/Virtualenvs/py38/lib/python3.8/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
ModuleNotFoundError: No module named 'contextlib' To install my python environment, I used pyenv with the following options (I need shared libs for some embedding)
I then create a virtualenv env using this pyenv python via (I also have the same exact "problem" with 3.9.1) I actually have my own markdown file for setting it all up, I'm sharing it here in case it's useful How to install pyenv and virtualenvInstall build requirementsSee pyenv's wiki here for an up to date list:
Install pyenvhttps://github.com/pyenv/pyenv-installer: Note: uses pyenv-virtualenv and not pyenv-virtualenvwrapper
or, directly from https://github.com/pyenv/pyenv#installation, Basically step1 only:
Install a python version via pyenvTo avoid getting errors like this when linking E+:
use
Do verify that Pyenv-virtualenvwrapper as a pyenv pluginhttps://github.com/pyenv/pyenv-virtualenvwrapper
Create a python venv
|
some environment variables that may be of interest:
|
I can also reproduce with the same command as the OP: $ PYCALL_DEBUG_FIND_LIBPYTHON=1 ruby -rpycall -ePyCall.builtins
DEBUG(find_libpython) find_libpython(nil)
DEBUG(find_libpython) investigate_python_config("python3")
DEBUG(find_libpython) libs: ["libpython3.8.so.1.0", "libpython3.8.so", "libpython3.8", "libpython"]
DEBUG(find_libpython) libpaths: ["/home/julien/.pyenv/versions/3.8.3/lib", "/home/julien/Virtualenvs/py38/lib", "", "/home/julien/Virtualenvs/py38", "/home/julien/Virtualenvs/py38/lib"]
DEBUG(find_libpython) dlopen("/home/julien/.pyenv/versions/3.8.3/lib/libpython3.8.so.1.0") = #<Fiddle::Handle:0x00005577803400d8>
paths_in_sys={'/home/julien/Virtualenvs/py38/lib/python3.8', '/home/julien/Virtualenvs/py38/lib/python38.zip', '/home/julien/.rvm/gems/ruby-2.5.5/gems/pycall-1.3.1/lib/pycall/python', '/home/julien/.pyenv/versions/3.8.0/lib/python3.8', '/home/julien/Virtualenvs/py38/lib/python3.8/lib-dynload'}
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 770, in <module>
main()
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 747, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 279, in addsitepackages
addsitedir(sitedir, known_paths)
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 202, in addsitedir
addpackage(sitedir, name, known_paths)
File "/home/julien/Virtualenvs/py38/lib/python3.8/site.py", line 170, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/home/julien/Virtualenvs/py38/lib/python3.8/site-packages/_virtualenv.py", line 41, in <module>
from importlib.util import find_spec
File "/home/julien/Virtualenvs/py38/lib/python3.8/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
ModuleNotFoundError: No module named 'contextlib' |
Ok, if I do that with python 3.9, which wraps stuff in Lib/site.py addpackage method in a try except block, I get the same fs_encoding error as the OP:
|
In my 3.8.3 version if I modify this: https://github.com/python/cpython/blob/6f8c8320e9eac9bc7a7f653b43506e75916ce8e8/Lib/site.py#L169-L170 by
Then it loads the sys correctly. Here is the output:
but it seems that it doesn't really work in real applications. One of my pycall call's logs this
|
I opened #135 as a result. |
Having similar issue on a virtualenv, using pandas directly in virtualenv python works, but when I try to import pandas in ruby I get different errors. Python 3.9.1 With pycall 1.3.1 and 1.3.0:
With 1.2.1
|
Hi, we're using pycall 1.3.0, with python 3.5.2 from a venv and ruby 2.6.3p62.
We're getting this error when running
PYCALL_DEBUG_FIND_LIBPYTHON=1 ruby -rpycall -ePyCall.builtins
With pycall 1.2.1 in the same setup we don't have the problem.
The text was updated successfully, but these errors were encountered: