27
loading...
This website collects cookies to deliver better user experience
Run
button, it blows up with an error but when running the script from the command line it runs with no errors, as it supposed to. $ python wierd_error.py
Traceback (most recent call last):
File "C:\Users\path_to_file", line 943, in <module>
import bcrypt
ModuleNotFoundError: No module named 'bcrypt'
Hey man, there's no bcrypt
module, just go and install it.
env
folder for a project to isolate it from globally installed packages.python -m venv env
$ source env/Scripts/activate
(env)
pip install
. They were installed to env
folder as they should, and I confirmed it via pip list
command to print out all install packages in the virtualenv
.$ pip list
Package Version
---------- -------
bcrypt 3.2.0 <-- It's there!
pip 21.1.1
setuptools 56.0.0
Run
button but runs smoothly from the command line both inside IntelliJ IDEA and PyCharm?Run
button explodes with an error.Pycharm is unable to recognize installed local modules, since python interpreter selected is wrong. It should be the one, where your pip packages are installed i.e. virtual environment.
I had installed packages via pip in Windows. In Pycharm, they were neither detected nor any other Python interpreter was being shown (only python 3.6 is installed on my system).
python.exe
inside virtual environment folder is located, and copied the full path.Project Structure
settings (CTRL+ALT+SHIFT+S) -> SDK's
-> Add new SDK
-> Add Python SDK
-> System interpreter
-> changed existing path to the one I just copied. Done!Run Configuration
to the one that was just created inside System Interpreter
under Project Structure
:venv
) that PyCharm provides because I already create it from the command line beforehand, that's why I change path inside System Interpreter.Virtual Environment
instead of creating it from command line (basically the same process as described above):Set Base Interpreter
to whatever Python version is running.
Make sure that Project SDK
(Project Structure
window) is set to the one from Virtual Environment
(Python 3.9 (some words)
).
Open Run Configuration
-> Python Interpreter
-> Use specific interpreter
path is set to python.exe
path from the venv
folder (e.g. newly created virtual environment
).
Note: When using such method, Bash commands not found for unknown for me reason.
$ which python
bash: which: command not found
() <- tells that you're currently in virtualenv
env
manually (python -m venv env
), Bash commands are working.env
, activate it via $ source env/Scripts/activate
and it works.