Ryan F
Ryan F

Reputation: 11

Pipenv Locking failed

Pipenv is failing to lock the Pipfile, either when installing modules or with pipenv lock

I am trying to set up pipenv to use in my projects at work. I use a corporate proxy and have a pip.ini config file set up, this has worked with pip for installs and virtualenv.

Not sure if this is an issue with the proxy, which works for pip installs. I've also read that there may be an environment variable I need to change.

I tried installing requests, and pipenv is able to create the environment and install the dependencies, but is not able to lock the Pipfile. It is able to install if I use --skip-lock. But if I go to install/update anything, or lock the file with pipenv lock (including --clear), it fails. Traceback is below, am I reading it right that its starting with an SSL issue?

    Traceback (most recent call last):
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\connectionpool.py", line 714, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\connectionpool.py", line 403, in _make_request
    self._validate_conn(conn)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\connectionpool.py", line 1053, in _validate_conn
    conn.connect()
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\connection.py", line 419, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Program Files\Python39\lib\ssl.py", line 501, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Program Files\Python39\lib\ssl.py", line 1041, in _create
    self.do_handshake()
  File "C:\Program Files\Python39\lib\ssl.py", line 1310, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\connectionpool.py", line 798, in urlopen
    retries = retries.increment(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
pipenv.patched.pip._vendor.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /pypi/charset-normalizer/json (Caused by ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\resolver.py", line 675, in <module>
    main()
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\resolver.py", line 661, in main
    _main(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\resolver.py", line 645, in _main
    resolve_packages(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\resolver.py", line 612, in resolve_packages
    results, resolver = resolve(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\resolver.py", line 592, in resolve
    return resolve_deps(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\utils\resolver.py", line 918, in resolve_deps
    results, hashes, internal_resolver = actually_resolve_deps(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\utils\resolver.py", line 692, in actually_resolve_deps
    hashes = resolver.resolve_hashes
  File "C:\Program Files\Python39\lib\functools.py", line 993, in __get__
    val = self.func(instance)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\utils\resolver.py", line 595, in resolve_hashes
    self.hashes[ireq] = self.collect_hashes(ireq)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\utils\resolver.py", line 566, in collect_hashes
    hashes = self.project.get_hashes_from_pypi(ireq, source)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\project.py", line 274, in get_hashes_from_pypi
    r = session.get(pkg_url, timeout=self.s.PIPENV_REQUESTS_TIMEOUT)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\requests\sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_internal\network\session.py", line 519, in request
    return super().request(method, url, *args, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\cachecontrol\adapter.py", line 76, in send
    resp = super().send(request, stream, timeout, verify, cert, proxies)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\patched\pip\_vendor\requests\adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
pipenv.patched.pip._vendor.requests.exceptions.ConnectionError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /pypi/charset-normalizer/json (Caused by ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)))

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\Scripts\pipenv.exe\__main__.py", line 7, in <module>
    # when invoked as python -m pip <command>
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\cli\options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\vendor\click\decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\cli\command.py", line 340, in lock
    do_lock(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\routines\lock.py", line 65, in do_lock
    venv_resolve_deps(
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\utils\resolver.py", line 859, in venv_resolve_deps
    c = resolve(cmd, st, project=project)
  File "C:\Users\J1RXF03\AppData\Roaming\Python\Python39\site-packages\pipenv\utils\resolver.py", line 728, in resolve
    raise RuntimeError("Failed to lock Pipfile.lock!")
RuntimeError: Failed to lock Pipfile.lock!

Upvotes: -1

Views: 2063

Answers (2)

Yared Birihanu
Yared Birihanu

Reputation: 11

Try clearing the cache for your package manager by running the following command:

pipenv --clear

If the above steps doesn't resolve the issue, the problem may be specific to pipenv so use a different package manager like 'pip".

I think either of the one will resolve the issue.

Upvotes: 1

Ryan F
Ryan F

Reputation: 11

The comment regarding setting the proxy value worked. I hadn't been using 'http://' in front in my config file. This however created a different issue with the SSL request. I was getting an error that said my request was attempting to use https instead of http. Someone recommended I set the environment variables HTTP_PROXY and HTTPS_PROXY in my terminal. This initially didn't solve the issue, until I read the wording of the error. Turns out I had to set both the above variables to the same value.

$ENV:HTTP_PROXY='http://proxy:port"
$ENV:HTTPS_PROXY='http://proxy:port"  <-- **not 'https://'**

The requests are now properly going through the proxy and completing, and then locking the file. Thanks all!

Upvotes: 1

Related Questions