bot icon indicating copy to clipboard operation
bot copied to clipboard

Virtual environment Import command

Open quintindunn opened this issue 2 years ago • 1 comments

As someone who spends a decent amount of time helping in the help channels, I often find people running into the issue of installing x library using pip but when they run import x they get the error ModuleNotFoundError: No module named 'x' from my experiences this is 99.9% of the time caused by someone using a virtual environment, and installing the library to the wrong environment or not running their program in that environment.

I think that a command that either links them to a page with some debug steps, or has the bot reply with said debugging steps would be very beneficial. This is because it's very hard to communicate the steps to debug this to people since most of the time they ones running into these issues are very new to Python. Utilizing a webpage could incorporate images to help guide people, or the bot could reply with a message that contains the links to these images.

I do understand that the help channels shouldn't always redirect people to other sources, but this issue, which can be solved in under two minutes with well documented solutions with images has caused me multiple conversation that span over 30 minutes by a long-shot.

quintindunn avatar Apr 29 '22 15:04 quintindunn

I do think this would be nice as a page on the site, and maybe a command linking to that page on the bot. I wrote up something a while back that could be a reference/starting point wookie184/python-guides/windows/import-error.md.

The main difficulty is that it's something where there are a lot of different situations and possibilities. Here are the sorts of questions I might ask myself in a help channel:

  • Is it just a typo/incorrect package name?
  • Have they actually installed the package (and did it install successfully)?
  • Are they actually getting an import error or is it just their linter not detecting it? (if it is just their linter how can they fix it, often in vscode they need to select the interpreter they are using, and maybe try reloading the window)
  • Did they install their package with pip or through their editor (and if they are installing with pip, which interpreter is that linked to)?
  • How are they running their code? In the terminal or through their editor?
  • Are they using a virtual environment (if so need to work out if they are not installing to that environment or not running in that environment)
  • How much do they know already? (might they need more information on how to open the terminal for example)
  • What OS are they using? If windows the py launcher might be helpful.
  • Are they using a dependency manager like poetry or pipenv?
  • What editor are they using? If it's Pycharm should they be instructed on how to install into the venv it creates or on how to change to use the system interpreter? Both options should be given probably, but need to explain the differences.

With knowledge on these things it's possible to work out what is most likely the issue and get to the solution in minimal steps. This would be harder to do with a guide so the scope, layout, and contents would have to be carefully considered.

wookie184 avatar May 15 '22 12:05 wookie184