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

Embedded 3.6.1 distribution cannot find _socket module #74631

Closed
ThomasS mannequin opened this issue May 23, 2017 · 4 comments
Closed

Embedded 3.6.1 distribution cannot find _socket module #74631

ThomasS mannequin opened this issue May 23, 2017 · 4 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@ThomasS
Copy link
Mannequin

ThomasS mannequin commented May 23, 2017

BPO 30446
Nosy @pfmoore, @tjguk, @zware, @zooba

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:

assignee = None
closed_at = <Date 2017-05-30.04:41:20.534>
created_at = <Date 2017-05-23.23:46:10.977>
labels = ['type-bug', 'invalid', 'OS-windows']
title = 'Embedded 3.6.1 distribution cannot find _socket module'
updated_at = <Date 2017-05-30.04:41:20.533>
user = 'https://bugs.python.org/ThomasS'

bugs.python.org fields:

activity = <Date 2017-05-30.04:41:20.533>
actor = 'ThomasS'
assignee = 'none'
closed = True
closed_date = <Date 2017-05-30.04:41:20.534>
closer = 'ThomasS'
components = ['Windows']
creation = <Date 2017-05-23.23:46:10.977>
creator = 'ThomasS'
dependencies = []
files = []
hgrepos = []
issue_num = 30446
keywords = []
message_count = 4.0
messages = ['294297', '294480', '294491', '294738']
nosy_count = 5.0
nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'steve.dower', 'ThomasS']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue30446'
versions = ['Python 3.6']

@ThomasS
Copy link
Mannequin Author

ThomasS mannequin commented May 23, 2017

Trying to import the socket module using the embedded distribution for 3.6.1, I get the error: <class 'ModuleNotFoundError'>: No module named '_socket'

Running with the standard interpreter works:

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]
 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import *
>>>

via an embedded C++ call, however, <class 'ModuleNotFoundError'>: No module named '_socket' is the error returned.

@ThomasS ThomasS mannequin added OS-windows type-bug An unexpected behavior, bug, or error labels May 23, 2017
@zware
Copy link
Member

zware commented May 25, 2017

I suspect you'll need to set sys.path (PySys_SetPath, I think, but trust the docs more than me). Try importing sys and printing sys.path to confirm.

@zooba
Copy link
Member

zooba commented May 25, 2017

I've been meaning to get to looking at this issue for a couple of days now, sorry.

There are two critical pieces here:

  • don't delete or move _socket.pyd
  • don't delete or move python36._pth (but possibly update it)

The first one should be obvious - I assume you haven't messed that bit up :)

The second one is the "static" way of setting sys.path, as Zach suggests. By default, it should include 'python36.zip' and '.', which is the directory containing python36._pth and python36.dll. If you move any of these around, sys.path will be automatically inferred, which could break things.

Further, if you move/remove python36._pth, the registry and environment will be used to locate files rather than only looking in the application directory. This may be bad.

One final tip - you can rename python36._pth to your_exe_name._pth if you want, and if you are embedding then you can get roughly equivalent behaviour using PySys_SetPath.

If none of this works, we'll need you to provide some information about your application, especially the code used to initialize the interpreter, import socket, and the layout of all the files in your app. (Right now, you're asking us to guess basically every detail that is relevant to the bug, hence we're replying with "read the docs" and "try everything" rather than a specific fix ;) )

@ThomasS
Copy link
Mannequin Author

ThomasS mannequin commented May 30, 2017

Thank you Steve and Zachary. The context you provided helped me track it down, so I have marked this closed. In case it benefits anyone in future as well, I ran into a subsequent topic where the C++ app was compiled in debug and hence the actual file being looked for was _socket_d.pyd which is not in the embedded distributable of course.

Thanks again for taking the time to provide your insights.

Thomas

@ThomasS ThomasS mannequin closed this as completed May 30, 2017
@ThomasS ThomasS mannequin added the invalid label May 30, 2017
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants