Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77197 > unrolled thread
| Started by | Marko Havu <marko.havu@jyu.fi> |
|---|---|
| First post | 2014-08-28 12:58 +0300 |
| Last post | 2014-08-28 12:58 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Py_SetProgramName() and prefixes Marko Havu <marko.havu@jyu.fi> - 2014-08-28 12:58 +0300
| From | Marko Havu <marko.havu@jyu.fi> |
|---|---|
| Date | 2014-08-28 12:58 +0300 |
| Subject | Py_SetProgramName() and prefixes |
| Message-ID | <mailman.13550.1409219949.18130.python-list@python.org> |
Hi,
I have a problem with Py_Initialize() not being able to find python in the path. Unless I use Py_SetProgramName() with the full path of the python interpreter, I get the following error message:
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 load the file system codec
ImportError: No module named ’encodings’
Is there a way of getting this to work without setting $PYTHONHOME? I am sure this worked for me before. The odd part is, I haven’t touched my python installation or environment variables. While doing some testing, I stumbled across some weird behavior on Python 3.3 and 3.4: Py_GetPrefix(), Py_GetPath() and other functions that return paths that are supposed to be set by Py_SetProgramName() all return just ”/”:
---------------- main.c ----------------
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[])
{
printf("path: %s\n", getenv("PATH"));
Py_SetProgramName(L"/anaconda/envs/python3.4/bin/python");
Py_Initialize();
wprintf(L"prefix: %s\n", Py_GetPrefix());
PyRun_InteractiveLoop(stdin, "<stdin>");
Py_Finalize();
return EXIT_SUCCESS;
}
----------------
Python 3.4 output (same with 3.3):
path: /anaconda/envs/python3.4/bin:/usr/bin:/bin:/usr/sbin:/sbin
prefix: /
>>> import sys
>>> sys.prefix
'/anaconda/envs/python3.4'
Python 2.7 output (setting correct path and changing char strings to wchar_t strings):
path: /anaconda/envs/python2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin
prefix: /anaconda/envs/python2.7
>>> import sys
>>> sys.prefix
'/anaconda/envs/python2.7’
Am I doing something wrong, or is this a bug in Python 3?
Kind regards,
Marko Havu
Back to top | Article view | comp.lang.python
csiph-web