ipython using python3.4 rather than python3.6 - python

I'm working on a ubuntu 14.04 machine with python3.6 installed. When I bring up the python shell using the "python3" command it invokes the python3.6.1 version as shown below and I'm successfully able to import pandas library
python3
Python 3.6.1 (default, Jun 13 2017, 21:37:44)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>>
But when I invoke the ipython shell by the command ipython3, it is using python 3.4.3 as shown below and I'm unable to import the pandas library. How do I tell ipython3 to use python3.6.1 version?
ipython3
Python 3.4.3 (default, Nov 17 2016, 01:11:57)
Type "copyright", "credits" or "license" for more information.
IPython 1.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import pandas
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d6ac987968b6> in <module>()
----> 1 import pandas
ImportError: No module named 'pandas'
How can I deal with multiple versions of python to avoid such problems?

I've had this problem when I've accidentally been in the wrong environment invoking ipython (or a new environment where it isn't installed yet). If you have ipython installed in your root environment or anywhere else on your path it will default to that instead, fairly silently.
To check do a 'pip list', where you are invoking ipython. If it isn't listed, install it with 'pip install ipython' and then rerun.

Related

altair python package gives "Illegal instruction" on Raspberry PI

In my RaspberryPI ZERO W I got strange error when trying to import altair module in python script.
pi#raspberrypi:~ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import altair
Illegal instruction
pi#raspberrypi:~ $ pip3 freeze
altair==4.2.0
Does anybody have an idea if there is a version, which works on RaspberryPi? Or any other idea why it is happening?
Illegal Instruction means that you are importing a C extension that is compiled incorrectly for the system you are using. Altair itself doesn't have any C extensions, but it depends on a number of libraries that do include C extensions, which you can see in its requirements.txt file:
entrypoints
jinja2
jsonschema>=3.0
numpy
pandas>=0.18
toolz
I would suggest trying to import each of these libraries to narrow-down which package is incorrectly installed, and then search for information on how to correctly install the problematic package on RaspberryPi ZERO.

Something wrong with my conda channel and leads to a tensorflow import error

I created a Conda environment with python 3.6 and venv and activated it. then installed tensorflow with
pip install tensorflow
However, there is something wrong with my python. Basically like when i run python i get:
Python 3.6.2 |Anaconda, Inc.| (default, Oct 5 2017, 07:59:26) [GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
but with python3.6 everything works fine:
Python 3.6.10 | packaged by conda-forge | (default, Apr 24 2020, 16:44:11) [GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>>
I basically want to type the "python" into my command line and to work fine with tensorFlow.
Something is really strange with the way you are doing this, you shouldn't need a venv on top of your environment and you should install tensorflow with a conda rather than a pip install (reason being conda is an environment manager and solves for all packages to work together, whereas pip may install or uninstall things in a way that messes up the whole environment solution; tldr, more likely to work). Try making a new environment and see how this works out
conda create -n tfenv tensorflow=2
if you instead want Python 3.6 (other one will use latest python that works with tensorflow, should be 3.7)
conda create -n tfenv python=3.6 tensorflow=2
then, as usual activate the environment with
conda activate tfenv

OpenCV not found in Jupyter Notebook, but found in Terminal [duplicate]

This question already has answers here:
Conda environments not showing up in Jupyter Notebook
(24 answers)
Closed 2 years ago.
I installed openCV in my environment using '''conda-forge'''.
It works in my terminal
❯ python
Python 3.8.2 (default, Mar 26 2020, 10:43:30)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
But it doesn't work on my Jupyter Notebook
import cv2
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-c8ec22b3e787> in <module>
----> 1 import cv2
ModuleNotFoundError: No module named 'cv2'
I am using Python 3.8.2. It shows on my conda list and the environment package list of anaconda. Please help.
Thank you #Trenton.
python -m ipykernel install --user --name Vision --display-name "Python (Vision)"
Then selecting the Python (vision) from Jupyter Notebook solved this!

Module detected by iPython but not Python in same virtual environment

I'm running a script from a Python 3.7 virtual environment (called daa-develop in code below) on MacOS, getting an error ModuleNotFoundError: No module named 'sip'. When then installing sip after, I get 'requirements already satisfied'.
The peculiar behaviour is that when I use IPython in the terminal, it's able to import sip, but not when I use Python in the terminal.
As below:
(daa-develop) :daa-develop $ python
Python 3.7.7 (default, Mar 26 2020, 10:32:53)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
import sip
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sip'
exit()
(daa-develop) :daa-develop $ ipython
Python 3.7.7 (default, Mar 26 2020, 10:32:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sip
In [2]:
Any ideas?
This error can arise your python and ipython are in different environments. It could have been that you installed sip in the same environment as ipython, and so ipython was able to find it. Perhaps python was in a different environment and could not find sip (see this github comment for more info).
Even if that is not the issue, miniconda makes it very easy to start fresh with new environments. I would suggest creating a new environment and re-installing ipython and sip.
conda create --name testing python=3.7 ipython sip
conda activate testing
python -c "import sip"
ipython -c "import sip"

How to use FEniCS in Jupyter Notebook or Spyder?

I have recently installed FEniCS using Docker with following command
Terminal> curl -s https://get.fenicsproject.org | bash
Every thing works well when I am in fenicsproject session. In this session when I use which python I get the following
fenics#7016ac685f58:~$ which python
/usr/bin/python
However, when I try to use the following command in Jupyter Notebook
from fenics import *
I get the following error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-66a9e72f2de9> in <module>()
2 # Poisson solver in Python using FEniCS
3 # import FEniCS
----> 4 from fenics import *
5 #
6 # create mesh and denfine functional space
ImportError: No module named fenics
I am using Python provided by anaconda, details about the python are given given below
Python 2.7.12 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
and which python gives me following path
h147:project0 vikas$ which python
/Users/vikas/anaconda/bin/python
I dont know how to solve this problem. Please help me.
I had the same problem. Something strange happens whenever I use fenics through Anaconda. I deactivated Anaconda and runned the fenics in the system. Worked perfectly.

Categories

Resources