I am trying to edit Libreoffice-calc sheets through a python script using the library oosheet. I've followed their documentation and it seems to have installed correctly. But when I run "from oosheet import OOSheet as S" in the python shell, I returns this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/herm/.local/lib/python2.7/site-packages/oosheet/__init__.py", line 30, in <module>
from com.sun.star.awt import WindowDescriptor
ImportError: No module named com.sun.star.awt
On my Ubuntu system (14.04 Trusty, LO 4.2.8.2), LibreOffice uses python 3. So this works in a terminal:
python3
>>> import uno
>>> from com.sun.star.awt import WindowDescriptor
But this fails:
python
>>> import uno
ImportError: No module named uno
The OOSheet web site does not say that it works on python 3, so you may need to switch to AOO, which still uses python 2. Or why not just use PyUNO directly instead of OOSheet.
Related
When calling a python script from within Pycharm my script runs successfully. However when I call the same script via my terminal I get an import error:
Macs-MacBook:src macuser$ python ./run_events.py
Traceback (most recent call last):
File "./run_events.py", line 3, in <module>
from functions import return_ga_data
File "/Users/macuser/PycharmProjects/ops-google-extract/src/functions.py", line 2, in <module>
import connect
File "/Users/macuser/PycharmProjects/ops-google-extract/src/connect.py", line 4, in <module>
from oauth2client.service_account import ServiceAccountCredentials
ImportError: cannot import name 'ServiceAccountCredentials'
I am not using an environment. Also I'm using python 3.7.
All my python scripts are in the same directory. My terminal's pwd is the same directory.
Tried:
Tried calling the script with python3 ./run_events.py but I get the same result.
Per an SO post about paths I added this to the top of connect.py:
import sys
sys.path.append('/Users/macuser/PycharmProjects/ops-google-extract/src/functions.py')
I still got the same result.
Why can I run the file without an import error from within my IDE but not via the terminal when using ./run_events.py?
Do you have python 2 installed as well? Type python --version in the terminal and see what you get? My guess is Pycharm might be configured to use python 3 while your default python in terminal is python 2, so your python 2 is lacking those modules that was installed for python 3. So when you execute your script in the terminal it's using python 2. If that's the case you can try,
py -3 ./myscript.py
I am getting below ImportError while running a python file.
ImportError: No module named osgeo.gdal_array
!/usr/bin/env python
from osgeo.gdal_array import BandReadAsArray
However, if i try to import same from command line, it runs fine.
$ which python
/home/hduser/anaconda2/bin/python
$ python
>>> from osgeo.gdal_array import BandReadAsArray
>>>
Also, please see the below where i am getting the same ImportError.
$ /usr/local/bin/python2.7
>>> from osgeo.gdal_array import BandReadAsArray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named osgeo.gdal_array
I figured out that there is something going on between different versions of python. But, i do not want to change the original source code.
How do i make my program run without changing anything within the code of calling python installed in anaconda explicitly?
I have a python script which runs another python script and this latter script imports a module. It fails to do so and returns the following:
Traceback (most recent call last):
File "/some/path/script.py", line 13, in
import Autodock as AD
File "/some/path/to/module/Autodock.py", line 30, in
import BALL
File "/usr/lib/pymodules/python2.7/BALL.py", line 1, in
from BALLCore import *
ImportError: /usr/lib/pymodules/python2.7/BALLCore.so: undefined symbol: _ZN4BALL25FragmentDistanceCollectorclERNS_9CompositeE
However it gets loaded successfully when I just open the python interpreter and enter this:
>>> from BALLCore import *
Other scripts which also run /some/path/to/module/Autodock.py (which is the script importing the module) run successfully. What makes them successfully import the module from the same module-path?
I need to excuse myself for not sharing so much code, because I have no clue where to look. Any guidance would be appreciated.
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/.
I decided to develop my home project in python 3.x rather than 2.x. So I decided to check, if it works under 3.1. I run python3.1 above my package directory and then:
>>> import fathom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "fathom/__init__.py", line 3, in <module>
from schema import Database
ImportError: No module named schema
when I enter fathom directory however schema can be imported:
>>> import schema
Also when I run python2.6 above my package directory I can do this:
>>> import fathom
My __init__.py has following import:
from schema import Database
from inspectors import PostgresInspector, SqliteInspector, MySqlInspector
Should I add something for python3.1?
Did you try a relative import?
from . import schema
from .inspectors import PostgresInspector
Works in Python 2.6 as well.
The 2to3 script can help you pinpoint more of these problems.