Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introducing Pipenv

Pipenv doesn't recognize virtual environment that was created by itself

I'm new to pipenv and it might be some very newbie problem I'm facing.

I'm using python 3.9 and installed pipenv using python3 -m pip install pipenv.

I have a project with a requirements.txt and after running pipenv install -r requirements.txt it was supposed to create a virtual environment but after running pipenv shell and pipenv run src/manage.py runserver it says:

Error: the command src/manage.py could not be found within PATH or Pipfile's [scripts]

The virtual environment was created at /Users/myuser/.local/share/virtualenvs/project1-iLzXCwVe and not at the working space. Is it possible it has something to do with that? Any way this can be solved?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

DId you mean to run:

pipenv run python src/manage.py runserver ?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

As mentioned above, you may have left off the python command in your execution.

Regarding the venv location, pipenv stores the virtual env information is managed through environment variables. If you also use virtualenvwrapper then venv will be stored in a <dirname>-hash directory at the WORKON_HOME location. In each of these pipenv venv directories there is a .project file that contains the location of the corresponding working directory.

Post back if you have more questions. Good luck!!

I think you might have forgot to add python to your pipenv run command. Here is an example of where I tried to do something similar and nothing was ran but I got the same command as you.

❯ tree
.
├── Pipfile
└── src
    └── cli.py

1 directory, 2 files
  │  ~/Development/play ▓▒░
❯ pipenv run src/cli.py
Error: the command src/cli.py could not be found within PATH or Pipfile's [scripts].
  │  ~/Development/play ▓▒░
❯ pipenv run python src/cli.py
/Users/joshstephens/Development/play
  │  ~/Development/play ▓▒░
❯ cat src/cli.py
import os

def print_cwd():
    print(os.getcwd())


if __name__ == '__main__':
    print_cwd()

  │  ~/Development/play ▓▒░