I'm trying to use paraview (http://www.paraview.org/) with python scripting in IPython.
When I'm trying to use it in a python shell it works just find but when I'm trying in IPython I've got the following error:
>>> import paraview.simple
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/gaspard/OpenFOAM/ThirdParty-2.2.2/platforms/linux64Gcc/paraview-3.12.0/lib/paraview-3.12/site-packages/paraview/simple.py", line 39, in <module>
import servermanager
File "/home/gaspard/OpenFOAM/ThirdParty-2.2.2/platforms/linux64Gcc/paraview-3.12.0/lib/paraview-3.12/site-packages/paraview/servermanager.py", line 43, in <module>
import paraview, re, os, os.path, new, sys, vtk
File "/home/gaspard/OpenFOAM/ThirdParty-2.2.2/platforms/linux64Gcc/paraview-3.12.0/lib/paraview-3.12/site-packages/paraview/vtk/__init__.py", line 1, in <module>
from vtkCommonPython import *
ImportError: libvtkCommonPythonD.so.pv3.12: cannot open shared object file: No such file or directory
>>>
The command I used were:
import sys
sys.path.append('/home/gaspard/OpenFOAM/ThirdParty-2.2.2/build/linux64Gcc/paraview-3.12.0/bin/')
sys.path.append('/home/gaspard/OpenFOAM/ThirdParty-2.2.2/platforms/linux64Gcc/paraview-3.12.0/lib/paraview-3.12/site-packages/')
import paraview.simple
Do you know why I've got a different behavior between the classic python shell and the IPython console? And how I can fix this?
You'll also need to set the LD_LIBRARY_PATH environment variable to point to the directory /home/gaspard/OpenFOAM/ThirdParty-2.2.2/platforms/linux64Gcc/paraview-3.12.0/lib/paraview-3.12/.
Related
I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:
Adding library path containing .py files to Tools>PYTHONPATH manager
Synchronizing the path
Updating module names list through Tools>Update Module names list
However, when I try to import modules from this library I get two types of errors:
import easy
Traceback (most recent call last):
File "<ipython-input-2-685519d35f15>", line 1, in <module>
import easy
File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
from .server import Server, InputProcessor
ValueError: Attempted relative import in non-package
The second type of error as follows:
from plxscripting.easy import *
Traceback (most recent call last):
File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
from plxscripting.easy import *
ImportError: No module named plxscripting.easy
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?
The python interpreter I was using is located to '~/miniconda2/bin/python',2.7.11.
The problem is as follows:
If the current directory is home directory, I start the python in command line and import skimage.filters library. It works perfectly.
Name:~ Name $ python
>>> import skimage.filters
>>>
But when I tried to cd to another directory and did the same thing. I would get a importError as follows:
Name:~ Name $ cd dir/
Name: dir Name $ python
>>> import skimage.filters
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Name/miniconda2/lib/python2.7/site-packages/skimage/filters/__init__.py", line 1, in <module>
from .lpi_filter import inverse, wiener, LPIFilter2D
File "/Users/Name/miniconda2/lib/python2.7/site-packages/skimage/filters/lpi_filter.py", line 7, in <module>
from scipy.fftpack import ifftshift
File "/Users/Name/miniconda2/lib/python2.7/site-packages/scipy/fftpack/__init__.py", line 95, in <module>
from .basic import *
File "/Users/Name/miniconda2/lib/python2.7/site-packages/scipy/fftpack/basic.py", line 12, in <module>
from . import _fftpack
ImportError: cannot import name _fftpack
>>>
It's really odd because the paths of the python interpreter and the sys.path of them are the same. I also tried os.chdir('home directory') to make sure the os.getcwd() of both are the same as well. I tried to update the libraries and reinstall them. But the problem is still there.
Solved by reinstalling Python.
Im trying to figured out this problem. Yesterday I installed PyScripter and since then, scripts doesnt work. When I run any script (in PyScripter or IDLE) and trying to "import arcpy", it gets this error:
import arcpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
File "C:\Python26\ArcGIS10.0\lib\arcgisscripting.py", line 81, in <module>
from RuntimeError import RuntimeError
ImportError: No module named RuntimeError
Have somebody any suggestion how to fix it?
Thanks to all very much!
Sounds like the module is not installed properly (or at all). To verify, do the following:
open a shell and start the python shell by typing python
(If this doesn't display an error, check that python is added to your system path or if it is even installed at all. But if you've used Python on said machine maybe system path issue)
enter the commmand help('modules')
review the list of modules that's returned to see whether arcpy is included
if not, then you may have to reinstall the module
When I try to import multiprocessing in Python 2.7.5 on OS X 10.6.8, I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/util.py", line 40, in <module>
from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags
I also tried to install python2.7.6 with homebrew, but this error still occurs.
It sounds like a circular import issue. Try adding this to the the rest of your imports:
from subprocess import _args_from_interpreter_flags
There is a comment above the function in subprocess.py:
# XXX This function is only used by multiprocessing and the test suite,
# but it's here so that it can be imported when Python is compiled without
# threads.
May be related.
I am trying to call some functions in openopt package for Python from R using the rJython package. I have the NumPy, SciPy, and OpenOpt installed for Python 2.7.4 on my 64 bit windows 7. Importing openopt from Python is OK.
However, when I run the codes:
library(rJython)
rJython <- rJython(modules='openopt')
rJython$exec("from openopt import GLP")
I got errors:
.jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named openopt
Of course I checked the sys.path values for the Python environment:
rJython$exec("import sys")
rJython$exec("pname = sys.path")
jython.get(rJython, "pname")
but I got:
[1] "C:\\Users\\myname\\Documents\\R\\win-library\\2.15\\rJython\\Lib"
[2] "C:\\Users\\myname\\Documents\\R\\win-library\\2.15\\rJython\\jython.jar\\Lib"
[3] "__classpath__"
[4] "__pyclasspath__/"
[5] "openopt"
[6] "C:/Users/myname/Documents/R/win-library/2.15/rJython"
These are absolutely not like the values of sys.path in Python itself. So I extended the sys.path by:
rJython$exec("sys.path.extend(['C:\\Python27\\lib\\site-packages\\openopt-0.45-py2.7.egg'])")
Then it seems that I need to add the numpy to sys.path:
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\__init__.py", line 10, in <module>
from oo import *
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\oo.py", line 4, in <module>
from LP import LP as CLP
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\LP.py", line 1, in <module>
from baseProblem import MatrixProblem
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\baseProblem.py", line 2, in <module>
from numpy import *
ImportError: No module named numpy
I then extended everything in the sys.path list of Python in rJython. But I still get further information:
Erro in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\__init__.py", line 10, in <module>
from oo import *
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\oo.py", line 4, in <module>
from LP import LP as CLP
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\LP.py", line 1, in <module>
from baseProblem import MatrixProblem
File "C:\Python27\lib\site-packages\openopt-0.45-py2.7.egg\openopt\kernel\baseProblem.py", line 2, in <module>
from numpy import *
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 154, in <module>
import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Python27\lib\site-packages
OK. The main question is: it seems like I cannot import a module from the site-packages. I can absolutely import basic modules in Python2.7.4. Any suggestion?
rJython is a package that does not call Python but Jython, which is not exactly the same thing. In particular, Jython programs cannot currently use CPython extension modules written in C, only those in pure Python.
This is why neither NumPy nor SciPy can be invoked via rJython.
However, rPython, a package with exactly the same interface as rJython does interact with the true Python. You should try that.
There is a caveat, though: it currently only runs on UNIX (Linux/Mac/...) environments, not on Windows. It is possible to have it installed on Windows and there are some instructions as to install it on such platform, but involves some manual configuration of scripts (essentially, to indicate which version of Python is to be used and the path where it is located) and compilation.