import numpy with python 2.7 - python

I installed additional python 2.7 on my mac and numpy-1.6.2 for python 2.7, however whenever I want to import numpy, it will import the numpy from the preinstalled python version on my Mac, the version is 1.6.1, can anybody tell me how can I change the import direction to numpy-1.6.2??

You must ensure that the library you've just installed and you're trying to import is in your PYTHONPATH. Also, doing things like that are not most optimal - consider using virtualenv and installing your libraries on per project basis to avoid issues like that and getting a lot more flexibility in managing them.

Check the path of your numpy package:
import numpy
print numpy.__path__
and then replace the entire contents with the downloaded numpy version 1.6.2, if the stuff in the resulting path looks similar to the numpy 1.6.2 download.
Otherwise just delete that stuff (that's in the path) or uninstall it and remove it through some other way and then use:
pip install numpy

Related

Different numpy version in Anaconda and numpy.__version__ in IPython Shell

I used How do I check which version of NumPy I'm using? to learn how to get the version of numpy. However, when I run conda list | grep numpy, I get:
numpy 1.15.2 py36ha559c80_0
numpy-base 1.15.2 py36h8128ebf_0
numpydoc 0.8.0 py36_0
However, when I run version from IPython shell, I get:
import numpy as np
np.__version__
Out: '1.13.3'
np.version.version
Out: '1.13.3'
np.version.full_version
Out: '1.13.3'
Why are the two versions different? Which one should I trust? Thanks for any help.
Please note that I am not using venv (i.e. virtual environment). I am directly accessing Anaconda's packages. So, there is no issue about versioning.
Here's what PyCharm is showing me:
As per Conda's version information on package doesn't correspond to __version__, here's __file__ and sys.path. Please note that I have hidden my name for privacy issues.
It seems that you have besides your python 3 environment in anaconda, another python with IPython and numpy installed.
It looks like that PyCharm and Anaconda see (correctly) the same numpy versions, while IPython which, I assume you didn't start from within your anaconda environment, sees another python installation with the older numpy. In fact, your output shows, that there is another python3.6 in C:\Users\... which doesn't belong to anaconda.
To make numpy 1.15 available in IPython you can either start IPython from within your anaconda environment by typing in the terminal (easier solution)
C:\>activate <your_anaconda_environment_name>
(<your_anaconda_environment_name>) C:\>ipython
or you make your local IPython load the modules from the anaconda environment by having a look at this answer. This will be not a recommended option in this case, given the resulting cross linkings of two python installations.
The issue is that PyCharm reads older python version from location App-data\roaming... What I did is that in start-up script, I added the following code.
print("Correcting sys paths now...")
paths = [
'C:\\Anaconda3\\python36.zip',
'C:\\Anaconda3\\DLLs',
'C:\\Anaconda3\\lib',
'C:\\Anaconda3',
'C:\\Anaconda3\\lib\\site-packages',
'C:\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
]
import sys
for path in reversed(paths):
sys.path.insert(0,path)
print("Completed correcting sys paths now...")
del path
del paths
Above code will force Python to read latest files from Anaconda. However, if you are using virtual environment, you would need to point to that environment.
If you want to know where is Python installed, you can run:
import os
import sys
os.path.dirname(sys.executable)
Above answer is inspired from conda python isn't using the numpy version I try install if I also specify that it should use python 2. It doesn't provide the solution. I have posted a solution above.

How can you import a local version of a python package?

I think I've found a bug in matplotlib. I'm using anaconda as a package manager, but had to download matplotlib from github in order to edit it.
How do I import my modified version of matplotlib in order to test it? I tried using
import /absolute/path/to/modified/matplotlib
, but that didn't work. Ideally I would like to create a conda environment that uses the modified matplotlib instead of the original, so I can easily switch between the two.
How do you test and run a modified version of an open source library, without messing up your original version of the package? Is there a way to import a library from an absolute path?
Try this
import sys
sys.path.append('/absolute/path/to/modified/matplotlib')
import matplotlib # modified
Another option not mentioned, if you just put the matplotlib module (copy or move) in the directory of your project, python will check there first, find the version you put there, and look no further. This is exactly the reason why you shouldn't name your files, for example, math.py.
You can install a local version by telling anaconda to install the tar-ball of the package directly, i.e.
conda install package-version-py27.tar.bz2
You might also be able to use the --use-local argument.
See: https://github.com/conda/conda/issues/5266, https://github.com/conda/conda/issues/1884

After installing NumPy in Python - I still get error: "no module named numpy"

I need to install and use the Python NumPy module (and then later the Pandas module) in order to process heavy data in Python.
I downloaded and installed ENTHOUGHT, but it wasn't what I wanted all that extra clutter of extra modules (which defeats the purpose of importing Python modules only as needed), but the uninstall did not work properly (i.e. it left garbage folders and ENTHOUGHT remnants all over my computer).
I have tried installing NumPy via EASY_INSTALL and PIP (two package managers if I understand correctly) - but with no success. Every time I try to run my program, I get the error: "no module named numpy".
I have searched the questions here and have tried to alter my ENVIRONMENT VARIABLE as per the following video, but again, no success:
https://www.youtube.com/watch?v=ddpYVA-7wq4
C:\Python34
...still the same error!
I downloaded Anaconda (with all its extra clutter and installed, but I don't like the development environment - I want my Vanilla Python IDLE to run Vanilla NumPy with no extra clutter modules...) and when I tried to again install Numpy I received a message that it was already installed with a path to:
C:\users\yoni\anaconda3\lib\site-packages
....so I ALSO added this PYTHONPATH to the ENVIRONMENT VARIABLE in hopes that it would now recognize where the NumPy installation was (currently with Anaconda3 - but I hoped to be able to import NumPy to my vanilla Python IDLE):
C:\Python34;C:\users\yoni\anaconda3\lib\site-packages
I don't find a clear answer - I see others have the same problem, and nothing is working for me. How can I finish this installation of NumPy so that it works for me when I do a simple import of module?
This is a temporary solution until you can resolve your path issue.
It will be environment specific.
import sys
sys.path.append('C:\users\yoni\anaconda3\lib\site-packages[PackageName]')
import PakcageName

Mac OS Mavericks numpy Version Issue

When I run 'pip freeze' it shows that numpy==1.8.1; however, when I start Python and import numpy and then check the version number via numpy.version.version I get 1.6.
This is confusing to me and it's also creating a problem for scipy and matplotlib. For example, when I attempt to do the following import 'from matplotlib import pyplot' I get an error saying 'RuntimeError: module compiled against API version 9 but this version of numpy is 6'. This I'm guessing has something to do with the numpy versions being wrong.
Any suggestions?
From our conversation in chat and adding path to .bashrc not working:
Putting:
/usr/local/bin first in /etc/paths will resolve the issue

How to import a module with a dotted path?

I want to import the paramiko module located in /usr/local/lib/python2.7/dist-packages. So, I imported it this way:
from usr.local.lib.python2.7.dist-packages import paramiko
I have an error syntax related to python2.7 (It considers 7 as a package located in python2 package)
I have both Python3.1.3 and Python2.7 installed. I program with Python3.1.3 only, however.
How can I resolve this problem ?
How about ?
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
import paramiko
UPDATED
The best solution is installing paramiko on Python3 env. Take a look at #DanielRoseman's answer. Or virtualenv is worth consideration. Here is a good tutorial. http://simononsoftware.com/virtualenv-tutorial/
I don't know why you think you need to include the full path. That directory will already be included in the Python path. You just need to do import paramiko.
Edit after comment Well you can't randomly import things that are installed for a different version. There are several backwards incompatibilities, and anything that has any compiled extensions will just not work at all.
You need to download and install paramiko for your 3.1 installation, rather than trying to use the 2.7 version. python3 pip install paramiko, as an example.
(Also, you shouldn't really be using 3.1. If you're using the Python 3 series you should upgrade to 3.4.)

Categories