Same import statement imports different packages in ipython vs jupyter - python

I am trying to import tifffile in jupyter. When I do
import tifffile
print(tifffile.__file__)
I get
/home/user/anaconda3/envs/myenv/lib/python3.7/site-packages/skimage/external/tifffile/__init__.py
However, when I run the same command in ipython, same conda environment, I get
/home/user/anaconda3/envs/myenv/lib/python3.7/site-packages/tifffile/__init__.py
How is this possible?? How do I make it so they both import the second one?

Related

VSCode - import errors and interpreter errors

I have several imports in my current code:
from flask import Flask
import datetime as dt
import numpy as np
import pandas as pd
When I run this in VSCODE I am getting this error:
However, running this in jupyter notebook has no problems. When I looked online it said to use python interpreter but when I go to do that I get this error:
And another error:
Anaconda prompt says modules/packages are installed but when I run pip install in default windows terminal it says pip has no module:
Delete and reinstall Python extensions according to the same problem on github.
The second problem is related to the location of your Python interpreter. You need to choose the correct interpreter. I still recommend using one Python version in one environment. You can use other Python versions in virtual environment, so it won't lead to confusion.

Error : "The kernel appears to have died. It will restart automatically."

I am facing an error which I do not know how to fix. I'm trying to get this piece of code to work on windows but I have this error appearing
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.plot()
Error: "The kernel appears to have died. It will restart automatically."
I just had the same error message appear while using Jupyter notebook. Based on what I read, I think it's suggested to reinstall pandas, NumPy and matplotlib (other libraries if necessary) and see if that works.
I had several other issues, so I reinstalled the Anaconda navigator.
You can just use py script instead of Jupyter but if you wanna use Jupyter try either reinstalling NumPy or update.
pip install -U numpy

Jupyter notebook (Python 3.6): ImportError: cannot import name 'prange'

I am using numba to speedup my code. It runs fine in the terminal. But when I try to run it inside jupyter notebook, it gives error for import numba prange. I am using Numba 0.38.1.
When I try import prange from the temrinal of jupyter, the import works fine.
Can someone please guide me what could be the issue. Thanks
From the terminal created from Jupyter
From the notebook
Can you try the import and operation in different cells?
It worked for me. See here

cv2 Module not Found Even though I downloaded it

I am currently in PyCharm and I have the following line of code:
import cv2
Nonetheless, it gives me the error No module named cv2
I went to Preferences > Project Interpreter > + then found and downloaded cv2 just fine. In the Project Interpreter it lists cv2 as installed. I am not sure why it still shows that the module doesn't exist. Is there some way to download cv2 via command line. I am on OS X 10.10.
Here is the code I have so far (all the other imports work just fine):
# Program for OCR
import numpy as np
import cv2
from matplotlib import pyplot as plt
I find that sometimes after installing a module in PyCharm it requires a restart in order for it to work. Also, if you do want to do it in the command line, try pip3 install cv2.

I cant import sklearn in Anaconda 2.3.0

I have the newest Anaconda 2.3 on a non-network-Linux-machine. Everything works fine besides
import sklearn
I then get back
----> 1 import sklearn
sklearn.py in <module>()
ValueError: Attempted relative import in non-package
I have to go into the /pkgs folder in anaconda and into scikit-learn to import from there. This works and whats even weirder, when I type
import
and the tabulator to show possible packages, sklearn is shown.
Might be that you're using another Python installation on your computer.
For instance, I have Python in my Anaconda environement and the other one by default. If execute: ~/anaconda/bin/python I can import sklearn without problems.
On the contrary if I execute /usr/bin/python and then try to export it I get the error message since I installed sklearn from Anaconda.
Check your PATH variable with typing $PATH on your terminal and check the order, if Anaconda is not the first one (or it's not there) type: export PATH="/path/to/anaconda/bin:$PATH"
I hope this works.

Categories

Resources