Search code examples
pythonpipvirtualenvpipenvpython-venv

Pipenv not creating Pipfile and not creating environment in right location


I'm trying to use pipenv to create a virtual environment for my python program. I have a folder on my desktop (we'll call it 'project') where I cd to. So basically I'm in C:\Users\my_user\Desktop\project\.

I write pipenv shell, upon which the I get:

Using C:/Python39/python.exe (3.9.0) to create virtualenv...
[   =] Creating virtual environment...created virtual environment CPython3.9.0.final.0-64 in 446ms
  creator CPython3Windows(dest=C:\Users\my_user\.virtualenvs\my_user-GweeH6qV, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\my_user\AppData\Local\pypa\virtualenv)
    added seed packages: pip==20.2.4, setuptools==51.0.0, wheel==0.36.2
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Successfully created virtual environment!
Virtualenv location: C:\Users\my_user\.virtualenvs\my_user-GweeH6qV
Launching subshell in virtual environment...
Microsoft Windows [Version 10.0.19041.746]
(c) 2020 Microsoft Corporation. All rights reserved.

(my_user-GweeH6qV) C:\Users\my_user>

Basically, it does make a virtual environment, but I notice that my Pipfile and Pipfile.lock (as well as a bunch of other files) are not in my project directory, but rather in the directory C:\Users\my_user.

Why is this the case? No matter what I do I can't seem to get my environment, and my pipfiles to be in the project directory on my desktop.

A possible reason for this could have been that I did easy_install.exe pip (or something along those lines) to install pip because I was having issues with it a while back.

Here are some of the things I've tried:

  1. running pipenv install ________ rather than pipenv shell
  2. moving the project folder to a different folder (downloads, documents) and running pipenv shell from there.
  3. Putting a folder in my project folder and then running pipenv shell from that folder. This actually did work although I dont want my pipenv to be in a subfolder of project, I want it to be in the project folder itself.

Solution

  • I fixed the problem by simply deleting the Pipfile and Pipfile.lock files that were in C:\Users\my_user, and then in my C:\Users\my_user\Desktop\project running pipenv install <package>.

    The reason for the issue was most likely that at some point I probably opened a pipenv in C:\Users\my_user, and since pipenv does not allow for virtual environments within virtual environments, it would not let me create one inside C:\Users\my_user\Desktop\project.