Why NO ModuleNotFoundError with conda? - python-3.x

Normally when I've done pip uninstall <module> if I then try to import the module I get a ModuleNotFoundError, for example:
dino#DINO:~$ python -c 'import mplfinance as mpf;print(mpf.__file__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'mplfinance'
However, after activating a conda environment, the import works fine even when the package is unstalled both with pip uninstall and with conda remove, either way, I get:
dino#DINO:~$ python -c 'import mplfinance as mpf;print(mpf.__file__)'
None
Can anyone tell me why the import is NOT raising an exception, even though there is no module there to import??
This behavior (lack of import exception) appears to be related somehow to having activated a conda environment.

Related

64bit MacOs After succesfully installing Pygame: ModuleNotFoundError: No module named 'pygame'

Python noob here. I've been trying to install pygame and pandas for a few hours now. Even with Conda I did not succeed. I have Python 3.8.5 installed.
I eventually tried through the terminal with these commands:
python -m pip install pygame==2.0.0.dev6
and
python -m pip install pandas
(this was a total guess by the way, but apparently it did something)
Results were succesfull:
Requirement already satisfied: pygame==2.0.0.dev6 in /opt/miniconda3/lib/python3.8/site-packages (2.0.0.dev6)
and
Successfully installed numpy-1.19.2 pandas-1.1.2 python-dateutil-2.8.1 pytz-2020.1
But, when I try to import either modules, I still get errors. Any ideas?
import pygame
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
import pandas
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Do I need to move the modules to the script folder or something? Or what do I even move? Thanks!
Ok.. Got it thanks to #matt.. after succesfully installing pygame, find the environment in which pygame is installed by entering 'which python'.
In my case it returned:
/opt/miniconda3/bin/python
Now I needed to make sure the VS console was pointing at the same environment, by checking which python interpreter it was using and selecting the correct one. More info:
how to check and change environment in VS Code

Pandas not working: DataFrameGroupBy ; PanelGroupBy

I have just upgraded python and I cannot get pandas to run properly, please see below. Nothing appears to work.
Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tqdm/_tqdm.py",
line 613, in pandas
from pandas.core.groupby.groupby import DataFrameGroupBy, \ ImportError: cannot import name 'DataFrameGroupBy' from
'pandas.core.groupby.groupby'
(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/groupby/groupby.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"code/analysis/get_cost_matrix.py", line 23, in
tqdm.pandas() # Gives us nice progress bars File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tqdm/_tqdm.py",
line 616, in pandas
from pandas.core.groupby import DataFrameGroupBy, \ ImportError: cannot import name 'PanelGroupBy' from 'pandas.core.groupby'
(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/groupby/init.py)
I guess you are using an older version of tqdm. Try using a version above tqdm>=4.23.4.
The command using pip would be,
pip install tqdm --upgrade
The problem is with the 0.25.1 version of pandas. Consider downgrading it to 0.24.0.
For more information read this
pip install --upgrade pandas==0.24.0

ModuleNotFoundError: No module named 'cassandra'

After installing cassandra driver by running the command:
sudo pip3 install cassandra-driver, I am getting the error ModuleNotFoundError: No module named 'cassandra' when I try to import the module by running the line cassandra.
I then tried to see what all modules are installed in pip3 by running the command pip3 freeze:
astroid==2.1.0
cassandra-driver==3.16.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==2.2.2
six==1.12.0
wrapt==1.10.11
Seeing no cassandra, I tried to import the visible module: cassandra-driver and then I ended up with the error:
File "<stdin>", line 1
import cassandra-driver
^
SyntaxError: invalid syntax
Also, when I do correct the hyphen issue with this:
__import__("cassandra-driver"), I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cassandra-driver'
My which python3 is: /usr/local/bin/python3 and my which pip3 is: /usr/local/bin/pip3
My OS is MacOS
How to install cassandra?
Note: I am following this documentation.
Did you try to run these demos (from those docs)?
"If successful, you should be able to build and install the extension (just using setup.py build or setup.py install) and then use the libev event loop by doing the following:"
>>> from cassandra.io.libevreactor import LibevConnection
>>> from cassandra.cluster import Cluster
>>> cluster = Cluster()
>>> cluster.connection_class = LibevConnection
>>> session = cluster.connect()
There is a probability that actual module is named differently, e.g. there is another external package called Pillow, but you import it with name "PIL".
In docs they are importing from cassandra.cluster
Docs I'm referring to
$ echo 'import cassandra.cluster' > cassandra.py && python3 cassandra.py
Traceback (most recent call last):
File "./cassandra.py", line 3, in <module>
import cassandra
File "/home/xxx/cassandra.py", line 4, in <module>
import cassandra.cluster
ModuleNotFoundError: No module named 'cassandra.cluster'; 'cassandra' is not a package
Using a different filename, the error disappears:
echo 'import cassandra.cluster' > tmp.py && python3 cassandra.py
So, for me, the error was that my own program overrode the package. O.o

ImportError: No module named 'mutiprocessing'

I am trying to import 'multiprocessing' and using python 3.5.3 but its gives error
Traceback (most recent call last):
File "ssser.py", line 7, in <module>
import mutiprocessing
ImportError: No module named 'mutiprocessing'
when i try to install multiprocessing module then i again error occure
i am using following command for installation
python3 -m pip install multiprocessing
and got error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-26ilgzih/multiprocessing/setup.py", line 94
print 'Macros:'
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-26ilgzih/multiprocessing/
however when i import "import multiprocessing" in terminal then no error occure but when i used in my file "ssscr.py" then it gives error
i am using geany,and python3 (IDEL) on raspberry pi3
Can any body help me how i can fix this error ?
For others who faces Similar error like
ModuleNotFoundError: No module named 'multiprocessing';
would also occur if you name your python file as multiprocessing.(as it makes ambiguity between your program name and actual module name)
Just rename your file and it will work (if you have dependency installed).
Seems like you are installing multiprocessing in the python 2 version. Could you use pip3 to install the package?
pip3 install multiprocessing
Also use the following command to check which pip you are using
$ ls -l `which pip`
$ ls -l `which pip3`
And to see if the package got correctly installed or not use
$ pip show pip
$ pip3 show pip
Update:
multiprocessing is built-in after python2.6
OP did a typo. It should be
import multiprocessing in place of import mutiprocessing

import rpy2.ipython meet error ModuleNotFoundError: No module named 'IPython'

My python version is 3.6. my OS is windows. After install rpy2 module, when I type import rpy2, got no issue. But when type import rpy2.ipython, got error as below:
>>> import rpy2.ipython
Warning (from warnings module):
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\rmagic.py", line 76
"either.")))
UserWarning: The Python package 'pandas' is strongly recommended when using `rpy2.ipython`. Unfortunately it could not be loaded, and we did not manage to load 'numpy' either.
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import rpy2.ipython
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\__init__.py", line 1, in <module>
from .rmagic import load_ipython_extension
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\rmagic.py", line 81, in <module>
from IPython.core.displaypub import publish_display_data
ModuleNotFoundError: No module named 'IPython'
Can help to figure out what's issue??
It seems that you are missing Ipython and pandas. Installing them should resolve your issue.
Run "pip install ipython" to install Ipython and run "pip install pandas" to install pandas.
Hopefully, this will solve your problem.
Happy Coding ~

Resources