LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Python numpy error (https://www.linuxquestions.org/questions/linux-newbie-8/python-numpy-error-4175571879/)

chris_crunch 02-10-2016 07:52 AM

Python numpy error
 
In Python, when I try...

Code:

>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chris/anaconda2/lib/python2.7/site-packages/numpy/__init__.py", line 175, in <module>
    from .version import git_revision as __git_revision__
ImportError: No module named version
>>>

Hmm? I mean, I have python-numpy installed

Code:

chris@chris-crunch:~/apps/caffe-master$ sudo apt install python-numpy
[sudo] password for chris:
Reading package lists... Done
Building dependency tree     
Reading state information... Done
python-numpy is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 15 not to upgrade.

So does this mean the file path is wrong or something?

chris_crunch 02-10-2016 08:00 AM

I think I made it worse...

Code:

chris@chris-crunch:~/anaconda2/lib/python2.7/site-packages$ rm -rf numpy
Code:

>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>>

I have googled and scrolled through many pages to try and find an answer to this. But all such attempts have failed...

Python 2.7.11 :: Anaconda 2.4.1 (64-bit)

153rd 02-10-2016 09:25 AM

Hey,

Try to reinstall python [sudo apt-get remove/uninstall] and then [sudo apt-get install] ..).
You can see if the system can find the library by calling [python --version], or [which python] in the CLI.

What did you do to make it worse?

You can confirm if your path is set right by doing [echo $PATH] in the CLI.

Cheers!

grail 02-10-2016 09:41 AM

I wonder if you installed the correct version for the python interpreter you are trying to use?

On my system I have the following options:
Code:

$ pacman -Ss python2?-numpy
extra/python-numpy 1.10.4-1
    Scientific tools for Python
extra/python2-numpy 1.10.4-1
    Scientific tools for Python

I would need to install the second version with the 2 in it if I were to use python 2.X and if I installed the first version it would be for python 3.X

So you might have to confirm either which version you have installed or which version of the python interpreter you are using to run your script?

chris_crunch 02-11-2016 03:20 AM

I think I worked out the problem.
I was using anaconda2 as my version of python.

This seems like a better idea to me, as if I'm messing around using commands like
Code:

conda install bleh
and something goes terribly wrong, it's separate from linux right?

And it did break actually. My mentor was looking at it today. He said "something ate conda" as the conda command didn't exist anymore. lol.

Okay so I'm trying to uninstall and reinstall Anaconda following the instructions on their website. Once I uninstalled it, the normal version of python was able to import numpy. So let's try with conda...

Okay guys conda is installed again. But I'm still using the default python. Does anyone know how I can change this so it uses the conda version? something like pythonpath variable?

chris_crunch 02-11-2016 03:56 AM

As in, I think it's here:

Code:

/home/chris/anaconda2/lib/python2.7
But I don't even know how to run python from here? Like I don't really know what I'm doing when I type in to the command line:

Code:

chris@chris-crunch:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Which is making this hard to google... Is this called launching a python interpreter or something?

EDIT: Okay, I think I've fixed it.
By doing this

Code:

conda create -n py27 python=2.7 anaconda
Then some stuff happenened.

I don't understand this:

Code:

# To activate this environment, use:
# $ source activate py27
#
# To deactivate this environment, use:
# $ source deactivate
#

But now this works!
Code:

chris@chris-crunch:~$ python
Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec  6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
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
>>> import numpy

Yay. Um, so my problem has been fixed by luck and internet scrolling. But if anyone could shed some light on what I actually did, I'd appreciate it. Thanks.

153rd 02-11-2016 04:03 AM

When you type "python", you basically tell your OS to look for the "python" program in the folders pointed to by your PATH - variable.
(I'm not experienced enough to give a more exact description)

Same as you use "grep", "ls", "man", etc. These are all binaries that exist in your /etc/bin folder for example.

So if you use "which python", you will get a directory of the python program that will be called if you type "python".
Confirm first that
Code:

/home/chris/anaconda2/lib/python2.7
is in fact the python library that's being called.

grail 02-11-2016 07:13 AM

You have mentioned a mentor, which would lead me to guess you are taking a course ... is there any reason you have not asked your teacher or mentor these questions?

In future you may want to alter your questions to advise that you are using anaconda instead of standard python otherwise you will receive answers (like my first one) that are irrelevant.

chris_crunch 02-11-2016 08:59 AM

Quote:

Originally Posted by grail (Post 5498528)
You have mentioned a mentor, which would lead me to guess you are taking a course ... is there any reason you have not asked your teacher or mentor these questions?

In future you may want to alter your questions to advise that you are using anaconda instead of standard python otherwise you will receive answers (like my first one) that are irrelevant.

No, I am not taking a course. It's a rather complicated situation. Hahaha.

Yeah sorry about that. At the time I didn't even realize what anaconda was. Infact I still don't really. It seems like much more than a python distribution.
Nevertheless tanks for your help. I would love to understand the theory more behind what is going on here, so I will continue to crawl through pages on google. (I'm a bit thick with this stuff). I know you have more important things to do that to teach everything to a newbie :p but if you could point me in the right direction to sources you think are good, I'm all ears.

Chris.

grail 02-11-2016 09:41 AM

Not at all an issue being a noobie (still there myself for many things:) ).

Just pointing out that asking for help for a particular thing (like python) but really meaning something else (like anaconda) makes it tough for those who do know about one or the other to help you :)

On a side note, is there a reason you went with anaconda instead of learning python first? ( I only ask as it seems a little strange to go after something not main stream if only in the learning phase )

Anyhoo, hope you get there :D


All times are GMT -5. The time now is 08:24 PM.