Interferences between anaconda and ubuntu 14.04 base python - python

I am very new with python, so please bear with me and be gentle
I recently installed anaconda and spyder in my ubuntu 14.04. When I call python in my console and I am having some different results when running python from the console and python from spyder
Results running from the console
if I call python
python
I get the following message:
Python 2.7.13 |Anaconda 4.4.0 (64-bit)| (default, Dec 20 2016, 23:09:15)
[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
and I can import pandas with no problem:
import pandas
with spyder however
Spyder
this is the opening message I get
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Imported NumPy 1.8.2, SciPy 0.13.3, Matplotlib 1.3.1
And if I try to import pandas
Import pandas
I get this
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
Clearly I have two different versions of python in my computer, I would like to have only one (Hopefully the one with anaconda since it comes with more dependencies I understand).

"Clearly I have two different versions of python in my computer, I would like to have only one (Hopefully the one with anaconda since it comes with more dependencies I understand)."
As a wise man once said, "It would be bad.". The link leads to a better answer but the short answer is that in 14.04, system level dependencies require its Python install. Removing it would likely break your operation system install.
https://askubuntu.com/questions/315015/how-can-i-remove-python-2-7-after-installing-python-3-3
As for pandas
Anaconda hopes to simplify the process especially for scientist so it installs pandas for you. You can see this by typing
help("modules")
You should see it in the Anaconda install but not in the Spyder install.
How does this work? If you
import sys; sys.path
a series of directories will be returned. pandas had been installed in one of the directories related to the Anaconda install. That directory will not be visible in the Spyder version.

Related

Python Import Different Libraries from Different Versions

I'm trying to develop a Python script, and I seem to be running into a conflict between two of the libraries that I want to include.
The first dependency that I have is pymoos (https://github.com/msis/python-moos), which is necessary to connect to my communication architecture. I've built the code and manually installed the resultant pymoos.so in the following places:
/usr/lib/python3.6/site-packages/pymoos.so
/usr/lib64/python2.7/lib-dynload/pymoos.so
/usr/lib64/python3.6/lib-dynload/pymoos.so
/usr/local/lib/python3.7/lib-dynload/pymoos.so
However, only python2.7 will allow me to 'import pymoos' from the interpreter. Attempting from either of the Python3 versions produces this:
Python 3.6.8 (default, Jun 11 2019, 15:15:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymoos
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_pymoos)
The second dependency is pydantic, which I have only managed to install using pip3, apparently meaning that it's only available from either of the versions of Python3 that I have installed. Attempting to import from Python2 gives the following:
Python 2.7.5 (default, Jun 11 2019, 14:33:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydantic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pydantic
Since I know where the pymoos.so library is, I think that my easiest path forward is to put that in the right place so it works with python3, but I can't seem to find the right place!
as per my comment:
it should be as simple as pip install path/to/pymoos/code, but you might be better off using a more widely used database library like asyncpg or psycopg.
Regarding having to use sudo, you might consider using virtualenv or similar to setup a dedicated python environment for your application.

python import successful in one terminal but fails in another

I downloaded and installed (build + make) a cython package, g2opy successfully. And when I tried checking if everything went well, I get this:
(cv) clmno#machine:~/OpenSource/python/g2opy$ python
Python 3.4.5 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:47:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g2o
>>> import numpy
>>> import cv2
So, I assume everything is fine and opened another terminal window. And tried importing the same module, but failed:
(cv) clmno#machine:~$ python
Python 3.4.5 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:47:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g2o
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'g2o'
Has this to do with the shared library (.so file)? If it was successfully imported, why would it fail the next time?
In the second terminal, you are running Python in a different directory compared to the first terminal. This suggests that the library you built is not in the Python path. It worked in the first terminal because the g2o library is in the directory where you are currently running Python. As Matthieu suggested, add "~/OpenSource/python/g2opy" to your PYTHONPATH environment variable.
In ~/.bashrc, add:
export PYTHONPATH=$PYTHONPATH:path/to/g2opy
then run source ~/.bashrc to update the environment variable in the current path.
If you installed the package locally, you need to set PYTHONPATH. Seems like it's not set properly.

Cannot find modules after installing Anaconda

I have installed Anaconda but still unable to use packages such as pandas and requests when running code on python.
When I input python on Terminal, it shows:
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And I also created a virtual environment and activate before opening the python shell:
conda create -n my-env python=3.6 anaconda
However, when reopening and running codes on Python, it kept saying "No module named 'pandas' or "No module named 'requests'" Does anyone know what the problem with this code is? Besides, I am not if version of Python has anything to do with this error? Is it because I am using 3.6.2 Python instead of 3.6.1?
Probably Anaconda became the default Python installation on your system. Specially when you are using a new environment, you have to install the modules you want in this new environment.
Try conda install pandas and, after that, import pandas

Python 2.7 Anaconda2 installed in windows

My Python 2 environmental path:
C:\Python27
C:\Python27\Scripts
My Python 3 environmental path:
C:\Python35
C:\Python35\Scripts
I set the environmental path for Anaconda2
C:\Users\User\Anaconda2\Scripts
C:\Users\User\Anaconda2
But when i typed python to enter the shell in cmd (C:\Users\user)
Importing the module of Anaconda like numpy or matplotlib
C:\Users\User>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named numpy
C:\Users\User>cd Anaconda2
C:\Users\User\Anaconda2>python
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
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
>>>
So i don't know
1.Why my module can't import while not in Anaconda2
2.It is said that the path of Python2 will overrdie the Python,so how to enter in the Python35 shell?
thanks everybody
Each Python installation has its own libraries. As you will see, you are not running the same Python 2.7 interpreter when you run with Anaconda active as you are without (I assume that's either the system Python or one you installed yourself).
Libraries installed in one interpreter aren't available to others. You should consider learning about conda environments to allow you to manage multiple projects easily.
The command deactivate should terminate the Anaconda environment, and if the Python 3 interpreter is first on your PATH you should then be able to run it. Another way would be to explicitly use the command
C:\Python35\python
which should work even with Anaconda active.
Caution: it's a long time since I used Windows, and I don't have current information on getting multiple Pythons to live happily together on Windows.

I cannot import igraph on python 2.6 after installation

I installed igraph for python 2.6 on OSX 10.7, but I cannot import igraph library.
It shows a import error:no module name igraph.
I have no idea. Please help me out.
Thanks.
However, I cannot run code with python. I make a code, and tried to run, such as, 'python ex.py'
OK, even though you didn't answer most of my questions, I'm pretty sure I can guess your problem. Your question title is "I cannot import igraph on python 2.6 after installation", but you're not trying to import it on python 2.6, you're trying on 2.7.
$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named igraph
>>>
$ python2.6
Python 2.6.7 (r267:88850, Jun 20 2012, 16:23:38)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
>>>
See the difference? OS X 10.7 (and 10.8) comes with three versions of Python: 2.5, 2.6, and 2.7. They're entirely independent installations, so when you installed igraph for Python 2.6, that didn't install it for your 2.5 or 2.7 installations.
The default, the one you get when you just run python, is 2.7. If you want a specific version, you have to run python2.6 instead.
So, you either need to run python2.6, or install igraph for 2.7.
As a side note, if you've installed any third-party Python installations, you're going to get yourself even more confused, so please, don't do that (or uninstall if you already have) until you really know what you're doing.

Categories