2

I am trying to run the following simple python script called 'main.py', through a pipenv virtualenv:

print("started.")

Executing pipenv run ./main.py --verbose (in pipenv venv) does not print anything to the console.
Through VS code, running pipenv run ./main.py --verbose outputs the following:

Creating a virtualenv and runnng main.py

That is to say, the python file seemingly does not run, expected 'started.' to be printed to the console, recieved nothing printed and program terminating.
This behaviour is also present when I attempt to run it through cmd, note the error produced with the --verbose flag:

Running main.py through pythin, pipenv and pipenv --verbose

I can run it sucessfully through just using python, however I really want to use pipenv to manage packages ect. I guess I'm mostly just curious at to:

  1. Why does this error occur?
  2. What does the following error, caused by running it with --verbose flag, mean?
    [5772:0107/202720.999:ERROR:broker_win.cc(56)] Error reading broker pipe: The pipe has been ended. (0x6D)
  3. How do I fix the issue?

I have reinstalled Pyhton, pipenv, and vscode - but have recieved the same results. Running the 'pipenv run' command both within the shell and outside the shell have the same results.

EDIT:

A Visual Studio Code issue

In the post above, after runing pipenv run main.py, vscode would always open. Whats stranger is, once vscode is uninstalled, the command works as expected! So an additional question of mine is,

  1. Why does vscode make this issue happen/what's the fix for being able to code using vscode and running pipenv run?

see bellow for what occurs when running pipenv run main.py with vscode initally closed:

running main.py while vscode is closed

This screenshot is after ~5mins of no action in iether the vscode console or the cmd console. The program never exited, and closeing the cmd also closed vscode.

3
  • The pipenv run command is not supposed to be run in a pipenv shell. Why are you doing that? Commented Jan 8, 2023 at 1:34
  • Ah, I was running it in a pipenv shell since the pipenv run on its own was causing the same issue, and I assumed that could be a fix. Will update the post, thank you. Commented Jan 8, 2023 at 12:39
  • Try pipenv run python main.py, as I commented on MingJie's answer. Commented Jan 10, 2023 at 9:58

1 Answer 1

0

pipenv run main.py means open the file in the ide you chose in the pipenv environment.

In this way, it just opened the file instead of run python file.

You need to use command python main.py to run it.

Sign up to request clarification or add additional context in comments.

3 Comments

This works, thanks! However, if there were imports in the main.py file (eg import foo) that only the venv had installed (through pipenv install foo) then running python main.py would throw a module not found. Is there a way to run main.py, using the pipenv environments python interpreter (that has this module installed)?
Have you choose the correct interpreter or run the file in your virtual environment? You can use Ctrl+Shift+P and search Python: Select Interpreter to choose your pipenv. I had a try just now, and there is no problem. Here is my step: 1. use command pipenv shell to active the environment in cmd. (You can also use the method I said upper, when you run the file, vscode will active environment automaticly) 2. use command pipenv install package 3. run the python file which imports this package.
@MingJie-MSFT, no, the pipenv run xxx command will execute a command xxx in the virtualenv. In your case(I guess you are on Windows), the shell opened the python source file. You should do like pipenv run python main.py if you are not already in the virtualenv, which I think what OP wants.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.