I see a ModuleNotFoundError: No module named 'xlwt'
I created a virtual environment and installed the packages using the following commands:
py -3 -m venv .venv
.venv\scripts\activate
python -m pip install xlwt
This error is not specific to this module. Even matplotlib, seaborn, spacy and other libraries are resulting in the same issue.
I have also checked for the interpreter using the "Select Interpreter" command. It seems like the right interpreter is being used - the one I just created.
Typing pip list in the terminal also lists these libraries as expected.
Running the code (ctrl+Alt+N) is when I see the ModuleNotFoundError.
Any idea if I'm missing something here?
Related
I have been having many issues with my python on macOS
(Im a beginner)
I want to use modules but every time I install something it says that the module doesn't exist even though its already installed I think it might be cause of the many versions of Python
python3 -- version says python 3.10.8 pip3 --version says python 3.9 (system) I have python 3.11.1 it does not work. In vscode I want to use packages I install them it says they don't exist. I change my VS-code python to all the different versions they still say they dont exist. I install the packages it says they already exist
from fastapi import FastAPI (, Request)
from fastapi import FastAPI, Request
ModuleNotFoundError: No module named 'fastapi'
I have tried using pyenv to manage versions and it says everything is on 3.11.1 but it doesn't change anything i have tried to remove the other versions of python but has been unsuccessful
Your terminal python, your vs-code terminal python and your project interpreter python could be diverse depends on how you install python.
To keep it simple, keep them watch same python.
On your terminal, go to your project root directory.
Type,
python -m virtualenv .venv
Virtualenv has created named '.venv'.
On terminal type source .venv/bin/activate to activate created python.
Now, your terminal python is same as your .venv.
Install all your dependency by hitting pip install -r requirements.txt
On your IDE, vs-code, set python interpreter to your ~/project/path/.venv/bin/python.
Now Every python see same python.
I am running Python version 3.7 and trying to create a stock prediction Python program using fbprophet. However, it doesn't want to install.
I have tried importing it using pip, through python, and using conda install. Nothing seems to work. Can I get some help here?
Showing that it isn't importing
Try with virtuanenv in python.
❯ python -m venv .venv
❯ source .venv/bin/activate
❯ pip install prophet
Then everything you installed will be in the virtual environment.
Here is the sample code.
from prophet import Prophet
print("imported successfully!")
And the output would be following:
❯ python sample.py
Fontconfig warning: ignoring UTF-8: not a valid region tag
Importing plotly failed. Interactive plots will not work.
imported successfully!
Keep in mind that, every library you installed will be only in the virtual env and you have to source first, before running the code.
I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store.
I tried running a script in PowerShell: Bash *.sh
This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.
Then I received this error:
ModuleNotFoundError: No module named 'scipy'
My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.
I ran this command to update pip:
python3 -m pip install --upgrade pip
I ran this command to get some modules:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
I also tried this command just in case:
pip install scipy
and got the result:
Requirement already satisfied ...
I ran the command pip list to make sure scipy was in the list (and it was there).
Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.
I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!
From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location.
Try using these commands in both your terminal (cmd in windows) as well as in you bash script:
import sys
print(sys.path)
This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.
You can also refer to this: Python modules not found over terminal but on python shell, Linux
I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using
OR
you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.
Update update: json_lines is not supported by python versions < 3 - my issue had pretty much nothing to do with environments. I am now using 3.9.1 and all is gucci.
Update: After using which python in my jupyter notebook and in my Terminal, I see that they are both using the same environment. As such I am still at a loss as to why my notebook cannot find json_lines.
I have two python environments on my computer, a default one and one I have for running my jupyter notebook on. I am trying to install the library, json_lines to the latter environment. I am not used the Anaconda environment manager.
On my Mac's Terminal I used the general pip install command pip install json-lines, but when I try to execute the following line of Python import json_lines in my notebook, I still receive the following error ImportError: No module named json_lines.
As I suspect I am not installing to the correct environment, I tried installing the library from inside my notebook with the following, import sys; !{sys.executable} -m pip install jsonlines.
However, this has not changed my dilemma.
Is there some way I can specify from my Terminal which environment to install to? or is it likely I am encountering a different issue to what I suspect?
The package for json_lines in pip in json-lines. Hence you could install it as:
$ pip install json-lines
It may be appropriate to use an isolated python environment for your particular project if you want to use particular conda libraries but without the whole package. In this instance, you would be able to use virtualenv. This will allow you to create an isolated python environment.
$ pip3 install virtualenv
You can call virtualenv to create a virtual python environment with the working name e.g. myvenv.
$ virtualenv myvenv
From here, you can set your terminal to use this python version. If you are on *nix:
$ which python
/usr/bin/python
$ source myvenv/bin/activate
(myvenv)$ which python
/.../myvenv/bin/python
This article can help you out.
https://janakiev.com/blog/jupyter-virtual-envs/
You need to create a virtualenv which will be used by your notebooks.
Using vscode, I have am using a venv and I have installed pygame in the venv. When I run pip list it shows up but when I try use it it gives an error saying that the package isnt installed. C