Import "…" could not be resolved MacOs – Environment
Question:
I have a repetitive problems almost in all my projects. I use separate environments for each project, then I install related libraries for them. I used pip
or brew
for installation. But most of the time I had this error: Import "..." could not be resolved
I’m sure I installed those packages because I see them in pip list
For example: I install numexpr
with both methods( brew install numexpr
and pip install numexpr
and after both, I have this package in my list:
% pip list
Package Version
---------- -------
numexpr 2.8.4
numpy 1.24.2
pip 23.0.1
setuptools 66.1.1
tk 0.1.0
wheel 0.38.4
and used in my code like this: import numexpr
But I really don’t know how should solve this repeated problem. I change my interpreter directory to : /user/bin/python3
or /opt/homebrew/bin/python3.10
or /user/local/bin/pyhton3
which are available for me but nothing changed
Answers:
Does this problem happen with other libraries like numpy? Also I’d recommend you make a virtual environment (see python venv) and use its interpreter and pip to manage dependencies for your project
As you said, you’re creating a separate environment for each project and I assumed you’re doing it correctly. After activating the virtual environment for the project and you’re installing the packages in the active virtual environment. All seems okay until now.
However, when choosing the interpreter, you’re not choosing the active env as I understand from your description. Instead, you’re choosing /user/bin/python3
etc. which is not an active environment’s python path.
After creating an environment and installing your desired package for each project, I suggest you write the terminal which python
-> and select the output path as an interpreter.
I would like you provide some actual python code that shows what causes the error? it’s hard to tell what’s happening if I don’t have any code as reference. Maybe you could do ‘python -m pip install pip –upgrade’ and try installing, and try the same command instead of pip put the module you want to import. I just would like some more solid references to work with.
provide as much context and reference.
If it works out please let me know!
I have a repetitive problems almost in all my projects. I use separate environments for each project, then I install related libraries for them. I used pip
or brew
for installation. But most of the time I had this error: Import "..." could not be resolved
I’m sure I installed those packages because I see them in pip list
For example: I install numexpr
with both methods( brew install numexpr
and pip install numexpr
and after both, I have this package in my list:
% pip list
Package Version
---------- -------
numexpr 2.8.4
numpy 1.24.2
pip 23.0.1
setuptools 66.1.1
tk 0.1.0
wheel 0.38.4
and used in my code like this: import numexpr
But I really don’t know how should solve this repeated problem. I change my interpreter directory to : /user/bin/python3
or /opt/homebrew/bin/python3.10
or /user/local/bin/pyhton3
which are available for me but nothing changed
Does this problem happen with other libraries like numpy? Also I’d recommend you make a virtual environment (see python venv) and use its interpreter and pip to manage dependencies for your project
As you said, you’re creating a separate environment for each project and I assumed you’re doing it correctly. After activating the virtual environment for the project and you’re installing the packages in the active virtual environment. All seems okay until now.
However, when choosing the interpreter, you’re not choosing the active env as I understand from your description. Instead, you’re choosing /user/bin/python3
etc. which is not an active environment’s python path.
After creating an environment and installing your desired package for each project, I suggest you write the terminal which python
-> and select the output path as an interpreter.
I would like you provide some actual python code that shows what causes the error? it’s hard to tell what’s happening if I don’t have any code as reference. Maybe you could do ‘python -m pip install pip –upgrade’ and try installing, and try the same command instead of pip put the module you want to import. I just would like some more solid references to work with.
provide as much context and reference.
If it works out please let me know!