Initialization of Python

Create issue
Issue #4 open
Keiichi Kuroyanagi created an issue

I installed PythonInR package in R version 3.2.2 (Platform: CentOS6), and then PythonInR initialized /usr/bin/python (Python Version 2.6.6). I want to initialize "~/.pyenv/shims/python". What would be a good way to do it?

Comments (9)

  1. Florian Schwendinger repo owner

    I never used CentOS6 but the following works on my Debian, therefore I assume something similar will work for you.

    Switching from python2.7 to python3.4

    1. Install the appropriate Python headers
      e.g. sudo apt-get install python3.4-dev

    2. Set the environment variable USESPECIALPYTHONVERSION and install again.



    Hope this works!

  2. Florian Schwendinger repo owner

    Also I never tested PythonInR with Python 2.6 that's why I put Python (>= 2.7.0) into the System Requirements.
    I would guess PythonInR works also with Python 2.6, but I never tried.

  3. Keiichi Kuroyanagi reporter

    Sorry my reply is late. Thank you for your reply. I understand a way described above, but I got the following errors in the case of the pyenv binary.

    > Sys.setenv(USESPECIALPYTHONVERSION="/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/bin/python3.5")
    > install.packages("PythonInR")
    wget: /home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/lib/ no version information available (required by wget)
    PythonInR_0.1-3.tar.gz' へ保存完了 [68977/68977]
    * installing *source* package ‘pack’ ...
    ** R
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    * DONE (pack)
    * installing *source* package ‘PythonInR’ ...
    **  パッケージ ‘PythonInR’ の解凍および MD5 サムの検証に成功しました 
    use special version
    python version is > 3
    PKG_LIBS= -L/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/lib -lpython3.5m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic
    PKG_CFLAGS=-I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/include/python3.5m -I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/include/python3.5m -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -pedantic -D -D PYTHON_IN_R_NO_EXPLICIT_LINKING
    ** libs
    gcc -std=gnu99 -I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/lib/R/include -DNDEBUG  -I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/include   -I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/include/python3.5m -I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/include/python3.5m -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -pedantic -D -D PYTHON_IN_R_NO_EXPLICIT_LINKING -fpic  -I/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/include  -c CToR.c -o CToR.o
    gcc -std=gnu99 -shared -L/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/lib/R/lib -L/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/lib -lgfortran -o CToR.o CastPyObjects.o CastRObjects.o GetPyObjects.o PyCall.o PyRunString.o PythonFunctions.o PythonInR.o Python_Explicit_Linking.o SetPyObjects.o -L/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/lib -lpython3.5m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic -L/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/envs/R/lib/R/lib -lR
    installing to /home/kuroyanagi/R/x86_64-pc-linux-gnu-library/3.2/PythonInR/libs
    ** R
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    Fatal Python error: Py_Initialize: Unable to get the locale encoding
    ImportError: No module named 'encodings'
    Current thread 0x00007fe0057e17c0 (most recent call first):
    Aborted (core dumped)
    ERROR: loading failed
    * removing/home/kuroyanagi/R/x86_64-pc-linux-gnu-library/3.2/PythonInRWarning in install.packages :
      installation of packagePythonInRhad non-zero exit status
    The downloaded source packages are in/tmp/RtmpIdoX5N/downloaded_packages>
  4. Florian Schwendinger repo owner

    Sorry I actually don't know but it looks like Python doesn't find the module encodings. You could try set PYTHONPATH AND PYTHONHOME like suggested here.

    Can you import the package encodings when you start python3.5 in the terminal?

    I will try to reproduce it.

  5. Florian Schwendinger repo owner

    For me the following did the trick,

    Sys.setenv(PYTHONHOME="/home/florian/bin/.pyenv/versions/anaconda3-2.4.1/bin") Sys.setenv(PYTHONPATH="/home/florian/bin/.pyenv/versions/anaconda3-2.4.1/lib/python3.5") where PYTHONHOME is the folder where the Python is located in your case it should be

    Sys.setenv(PYTHONHOME="/home/kuroyanagi/.pyenv/versions/anaconda3-2.4.1/bin") and PYTHONPATH where the packages are located (I just searched for the folder encodings)

    Please let me know if this works.

  6. Keiichi Kuroyanagi reporter

    Sorry my reply is late. Thank you for your advice. I tried the above setting, but I got the ERROR message. I gave up to use pyenv binary. I hope that PythonInR package will support pyenv environment officially in the future. Sorry for bother you.

  7. Florian Schwendinger repo owner

    Sorry it didn't work. But thank you for reporting this issue! I will try to fix it as soon I find time for it.

  8. Ulysses Ledezma

    I think i had a similar issue in Windows 10. The same error, no module named encodings.

    I solved it by listing the paths to: PythonLocation, and the folders Lib, DLLs, and Scripts

    library("PythonInR") Sys.setenv(PYTHONPATH="C:/PythonEnv/SPOTFIRE_PYTHON;C:/PythonEnv/SPOTFIRE_PYTHON/DLLS;C:/PythonEnv/SPOTFIRE_PYTHON/Scripts;C:/PythonEnv/SPOTFIRE_PYTHON/Lib;") pyConnect(pythonExePath="C:/PythonEnv/SPOTFIRE_PYTHON/python.exe")

  9. Log in to comment