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
import of site.py fails on startup #47529
Comments
In pythonrun.c, initstdio injects 'open' into builtins. However, Traceback (most recent call last):
File "j:\python30\lib\site.py", line 518, in <module>
main()
File "j:\python30\lib\site.py", line 501, in main
known_paths = addsitepackages(known_paths)
File "j:\python30\lib\site.py", line 281, in addsitepackages
addsitedir(sitedir, known_paths)
File "j:\python30\lib\site.py", line 178, in addsitedir
addpackage(sitedir, name, known_paths)
File "j:\python30\lib\site.py", line 141, in addpackage
f = open(fullname, "rU")
NameError: global name 'open' is not defined |
This happens if the site-packages directory contains a .pth file. This was unnoticed because the usual message |
Attached patch writes the "'import site' failed" message to libc stderr The initial problem still remains: site.py cannot use the "open" builtin. |
We could:
|
Here's my patch for the problem. |
Well, it would be interesting to know why r62778 has exactly the |
It was probably done so that importing _bytesio would actually work in |
Benjamin is right. site.py imports the io module before _bytesio and As for compiling _bytesio and _stringio into the main binary, you should |
On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson
Or you could use _warnings which is already compiled into the binary. |
On Mon, Aug 25, 2008 at 12:48 PM, Brett Cannon <report@bugs.python.org> wrote:
How would that help the problem of site using open() when it can't?
-- |
On Mon, Aug 25, 2008 at 10:49 AM, Benjamin Peterson
<report@bugs.python.org> wrote:
>
> Benjamin Peterson <musiccomposition@gmail.com> added the comment:
>
> On Mon, Aug 25, 2008 at 12:48 PM, Brett Cannon <report@bugs.python.org> wrote:
>>
>> Brett Cannon <brett@python.org> added the comment:
>>
>> On Mon, Aug 25, 2008 at 6:40 AM, Benjamin Peterson
>> <report@bugs.python.org> wrote:
>>>
>>> Benjamin Peterson <musiccomposition@gmail.com> added the comment:
>>>
>>> We could:
>>>
>>> 1. Use _fileio._FileIO directly.
>>> 2. Use os.open.
>>> 3. Initialize the stdio streams before importing site. This seems like
>>> the best option, although I haven't run all the tests yet.
>>>
>>
>> Or you could use _warnings which is already compiled into the binary.
>
> How would that help the problem of site using open() when it can't?
>> Sorry, replied to the wrong email. It was meant as a reply to Amaury's |
IMO, it's unacceptable to be running Python code before the stdio |
Here's a patch that builds _bytesio and _stringio right into the binary. |
But shouldn't the two extension modules be removed from setup.py? |
Yes, indeed. |
Look good to me, and python-dev accepted the patch. So, go ahead and |
Fixed in r66239. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: