ModuleNotFoundError: No module named '_socket' for python 3.10.7

Viewed 31

So I'm trying to run a python function through my C++ program in visual studio 2022:

if (SendMessage(download, BM_GETSTATE, 0, 0)) {
            Py_Initialize();
            // CODE TO RUN PYTHON FUNCTION
            PyObject* output = PyUnicode_FromString("C:\\Users\\Elliot Scher\\Desktop");
            PyObject* ytlink = PyUnicode_FromString("https://www.youtube.com/watch?v=G9cyeZfLeQc&ab_channel=FIRSTRoboticsCompetition");
            PyObject* pName, * pModule, * pFunc, * pArgs, * pValue;
            pName = PyUnicode_FromString("Downloader.py");
            pModule = PyImport_Import(pName);
            PyErr_Print();
            pFunc = PyObject_GetAttrString(pName, "download");
            pArgs = PyTuple_Pack(2, ytlink, output);
            pValue = PyObject_CallObject(pFunc, pArgs);
            Py_Finalize();
        }

But i'm getting this error which comes from the PyErr_Print call: ModuleNotFoundError: No module named '_socket'

Here is the Traceback:

Traceback (most recent call last):
  File "C:\Users\Elliot Scher\Desktop\Work\Code\Practice\c++\source\repos\YTDownloader\x64\Debug\Downloader.py", line 1, in <module>
    from pytube import YouTube
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\__init__.py", line 13, in <module>
    from pytube.streams import Stream
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\streams.py", line 16, in <module>
    from pytube import extract, request
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\extract.py", line 10, in <module>
    from pytube.cipher import Cipher
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\cipher.py", line 21, in <module>
    from pytube.helpers import cache, regex_search
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\lib\site-packages\pytube\helpers.py", line 10, in <module>
    from urllib import request
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\urllib\request.py", line 88, in <module>
    import http.client
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\http\client.py", line 71, in <module>
    import email.parser
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\email\parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\email\feedparser.py", line 27, in <module>
    from email._policybase import compat32
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\email\_policybase.py", line 9, in <module>
    from email.utils import _has_surrogates
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\email\utils.py", line 29, in <module>
    import socket
  File "C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\Lib\socket.py", line 51, in <module>
    import _socket
ModuleNotFoundError: No module named '_socket'

I've tried modifying the environmental variable PYTHONPATH to be

C:\Users\Elliot Scher\AppData\Local\Programs\Python\Python310\DLLs which is where _socket is but it hasn't worked. Has anyone encountered this before and know how to fix it?

0 Answers
Related