ipython looks into a virtualenv of a different python verion for some reason - ipython

so i had ipython and it worked fine for a while. Then I used buildout to install ipdb.
The case is: ipython and python2.7 systemwide
naked-python virtualenvs in the home folder.
A plone instance in the home folder using virtualenv of python2.4 from the naked-python i mentioned
now i try to run ipython and i get
fakedrake#fakedrake-arch ~ $ ipython
/home/fakedrake/python/parts/opt/lib/python2.4/pprint.py:39: RuntimeWarning: Python C API version mismatch for module cStringIO: This Python has API version 1013, module cStringIO has versi
on 1012.
from cStringIO import StringIO as _StringIO
/home/fakedrake/python/parts/opt/lib/python2.4/string.py:528: RuntimeWarning: Python C API version mismatch for module strop: This Python has API version 1013, module strop has version 1012
.
from strop import maketrans, lowercase, uppercase, whitespace
/home/fakedrake/python/parts/opt/lib/python2.4/unittest.py:51: RuntimeWarning: Python C API version mismatch for module time: This Python has API version 1013, module time has version 1012.
import time
/home/fakedrake/python/parts/opt/lib/python2.4/heapq.py:132: RuntimeWarning: Python C API version mismatch for module itertools: This Python has API version 1013, module itertools has versi
on 1012.
from itertools import islice, repeat
/home/fakedrake/python/parts/opt/lib/python2.4/bisect.py:82: RuntimeWarning: Python C API version mismatch for module _bisect: This Python has API version 1013, module _bisect has version 1
012.
from _bisect import bisect_right, bisect_left, insort_left, insort_right, insort, bisect
/home/fakedrake/python/parts/opt/lib/python2.4/heapq.py:306: RuntimeWarning: Python C API version mismatch for module _heapq: This Python has API version 1013, module _heapq has version 101
2.
from _heapq import heappush, heappop, heapify, heapreplace, nlargest, nsmallest
Traceback (most recent call last):
File "/usr/bin/ipython", line 26, in <module>
import IPython.Shell
File "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 58, in <module>
__import__(name,glob,loc,[])
File "/usr/lib/python2.7/site-packages/IPython/ipstruct.py", line 17, in <module>
from IPython.genutils import list2dict2
File "/usr/lib/python2.7/site-packages/IPython/genutils.py", line 20, in <module>
import doctest
File "/home/fakedrake/python/parts/opt/lib/python2.4/doctest.py", line 99, in <module>
import unittest, difflib, pdb, tempfile
File "/home/fakedrake/python/parts/opt/lib/python2.4/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/home/fakedrake/python/parts/opt/lib/python2.4/random.py", line 41, in <module>
from warnings import warn as _warn
File "/home/fakedrake/python/parts/opt/lib/python2.4/warnings.py", line 258, in <module>
simplefilter("ignore", category=OverflowWarning, append=1)
NameError: name 'OverflowWarning' is not defined
If you require any further info regarding the problem just tell me, i dont know wht else might be relevant...
(i run arch-linux)

Why do you have both python2.4 and python 2.7 libraries?? When ipython (v2.7) is importing doctest, it's moving into a python2.4 library. I'd inspect your PYTHONPATH environment variable, as well as sys.path i.e.
import sys, os
print '\n'.join( [p for p in sys.path ] )
print '\n'.join( [[ for
The order of this is important. Figure out why doctest is being imported from that python2.4 directory, and then remove that directory from sys.path. According to here, OverflowWarning is removed upon the upgrade to python2.5

Related

I am getting an error after importing pytest

i just installed pytest and i tried using it and it was giving me errors. i uninstalled it and installed it again and it was giving me the same errors as i tried importing it
import pytest
Traceback (most recent call last):
File "C:/Users/user/AppData/Roaming/JetBrains/PyCharmCE2021.1/scratches/scratch_1.py", line 1, in <module>
import pytest
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytest\__init__.py", line 7, in <module>
from _pytest.assertion import register_assert_rewrite
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\_pytest\assertion\__init__.py", line 10, in <module>
from _pytest.assertion import rewrite
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\_pytest\assertion\rewrite.py", line 26, in <module>
import py
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\py\__init__.py", line 14, in <module>
from py._vendored_packages import apipkg
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\py\_vendored_packages\apipkg\__init__.py", line 12, in <module>
from .version import version as __version__
ValueError: source code string cannot contain null bytes
can you please help me with what to do, or suggest another library just like pytest where i test my applications.
Thanks for your contribution
check if you installed pytest in the same pyenv you are using. Run pip list comand and check there is pytest there
It might be issue with environment in pyenv. Try to create new one. In PyCharm it is File -> Settings -> Project -> Python Interpreter -> Add

Cannot import Tensorflow with Eclipse on Ubuntu16.04

The bug happens when I try to import Tensorflow on Eclipse. Tensorflow can
be imported when I directly run the python code without using IDEs (I test it and it works perfectly). I've also tested my codes on PyCharm, it's fine with Pycharm....
I've tested the LD_LIBRARY_PATH,PATH,CUDA_HOME variables with echo. I also tried to directly append the cuda libraries into the Ecplipse pydev interpreter setting. So it is really confusing me. I did face a similar question with another machine, but I solved it by modifying the ~/.bashrc file.
I'm using Ubuntu16.04, python2.7,eclipse Neon3, GTX1080ti.
Any ideas? Following is the bug information:
Traceback (most recent call last): File "/home/zernmern/workspace/test/p1/test.py", line 2, in <module>
import tensorflow as tf
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/zernmern/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in
swig_import_helper_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
Please let me know if more information is needed xD.
Ubuntu 16.04 uses Python 3.5 as the default system version of Python. You say that you are using Python 2.7. Did you install that yourself? It doesn't come with the OS. (And if you don't have a compelling reason to stay with Python 2.7, I would encourage you to switch to Py 3.x anyway, especially since you're working with a cutting-edge package like TensorFlow.)
Once you have two versions of Python on your system, it's easy to lose track of which packages you installed to which version of Python. I would check to see whether you happen to have installed TensorFlow, or parts of it, to the system Python 3.5 instead of your Python 2.7.
Finally, I find the solution from 'PyCharm cannot find library'
As the user 'Laizer' suggested:
The issue is that PyCharm(Here is Eclipse) was invoked from the desktop, and wasn't getting the right environment variables. Solution is to either:
invoke from the command line(i.e. Directly start eclipse by sh),
create a script to set environment and then invoke, and make a link to that script on the desktop,
or set environment variables on the desktop item

Tensorflow with Cuda, libcudart.so.7.5: cannot open shared object. eclipse (Liclipse)

When I import tensorflow in Liclipse I get the following error:
Traceback (most recent call last):
File "/home/user/Documents/workspace/project", line 13, in <module>
import tensorflow as tf
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 45, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: libcudart.so.7.5: cannot open shared object file: No such file or directory
I have correctly installed tensorflow and cuda and both work fine from the terminal.
Tensorflow was installed via pip and I am using cuda 7.5 and cuDNN v4 and
I am using ubuntu 14.04.
The cuda samples compile and run perfectly as does tensorflow outside of Liclipse.
I have added cuda to both my path and LD_LIBRARY_PATH in .bashrc:
export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:LD_LIBRARY_PATH
I have the Liclipse python interpreter set up as:
/usr/bin/python-2.7
Any help would be much appreciated.
For the record, I had the same problem using Python 3 + PyDev + Eclipse (which I believe might be similar to Liclipse in this respect); what helped in my case was to add the cuda lib folder to my PYTHONPATH when running the IDE, e.g.,
PYTHONPATH=$PYTHONPATH:/usr/local/cuda/lib64 ./myEclipseFolder/eclipse
That made PyDev offer me the cuda lib folder for inclusion when setting up the Python interpreter, and then my tensorflow scripts worked.
Not a solution, but a work around. I'm simply running my scripts from the terminal. Its a pain for debugging but I am still unable to get TF to work with Liclipse.

Scipy and CX_freeze - Error importing scipy: you cannot import scipy while being in scipy source directory

I'm having trouble compiling an exe while using cx_freeze and scipy. In particular, my script uses
from scipy.interpolate import griddata
The build process seems to complete successfully, however when I try to run the compiled exe, I get the following message.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "gis_helper.py", line 13, in <module>
File "C:\Python27\lib\site-packages\scipy\__init__.py", line 103, in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter.
After looking at scipy\ _init__.py file, there is the following:
if __SCIPY_SETUP__:
import sys as _sys
_sys.stderr.write('Running from scipy source directory.\n')
del _sys
else:
try:
from scipy.__config__ import show as show_config
except ImportError:
msg = """Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter."""
raise ImportError(msg)
I'm not entirely sure what is the problem here however although it seems that the erros is being thrown because there is a problem with the scipy config file. Possibly not being included in the build process. I'm quite a novice and hoping someone more experienced with generating build using cxfreeze can shed some light on this.
Incidentally, the scipy in use was installed from binaries here.
i have had the same issue. I added this code to the setup.py generated by cx_freeze:
import scipy
includefiles_list=[]
scipy_path = dirname(scipy.__file__)
includefiles_list.append(scipy_path)
Then, used includefiles_list as part of the build_exe parameter:
build_options = dict(packages=[], include_files=includefiles_list)
setup(name="foo", options=dict(build_exe=build_options))
I add the same problem and solved it using fepzzz method and including some missing packages:
additional_mods = ['numpy.matlib', 'multiprocessing.process']
includefiles = [(r'C:\Anaconda3\Lib\site-packages\scipy')]
setup(xxx, options={'build_exe': {'includes': additional_mods, 'include_files': includefiles}})
And using version 5.0.2 of cx-Freeze package, which solved an error when importing multiprocessing.process

Pip mixup of python versions

I recently installed python 3.4 using this custom installation guide, the system had python 2.6 as default. Today i needed to install tldextract to python2.6
I did that using pip pip2.6 install tldextract but after i tried to import the module the import failed with this error.
Traceback (most recent call last):
File "process.py", line 12, in <module>
import tldextract
File "/usr/lib/python2.6/site-packages/tldextract/__init__.py", line 1, in <module>
from .tldextract import extract, TLDExtract
File "/usr/lib/python2.6/site-packages/tldextract/tldextract.py", line 70, in <module>
from urllib.request import urlopen
ImportError: No module named request
That seems to be the python3.4 version of tldextract since it is trying to find the request module in urllib. So i guess pip installed the wrong version of the module, how can i fix this? Or remove python 3.4 alltogether.
tldextract has the following code block in the source repo, and the line numbers match:
try: # pragma: no cover
# Python 2
from urllib2 import urlopen
from urlparse import scheme_chars
unicode = unicode
except ImportError: # pragma: no cover
# Python 3
from urllib.request import urlopen
So it looks like the Python 2 branch is throwing an exception for some unknown reason and it's failing over to Python 3. I would start by looking why that might be.