I have installed odoo in my server that has Python 2.7.9. When I try to launch the daemon, I get this error:
root#des [/opt/odoo/openerp]# /etc/init.d/odoo start
Starting Odoo Server Daemon (odoo-server): [ OK ]
root#des [/opt/odoo/openerp]# 'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/opt/odoo/openerp-server", line 2, in ?
import openerp
File "/opt/odoo/openerp/__init__.py", line 90
from . import models
^
SyntaxError: invalid syntax
This is Python information:
root#des [/opt/odoo/openerp]# python
Python 2.7.9 (default, Apr 2 2015, 20:06:47)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
And this is my environment:
root#des [/opt/odoo/openerp]# uname -a
Linux des.desytec.com 2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux
EDIT:
Thanks to Tevfik answer, I have solved the error, however, now a syntax error is produced in Python libraries. How is this possible and hot can I solve it?
root#des [/usr/local/lib/python2.7]# /etc/init.d/odoo start
Starting Odoo Server Daemon (odoo-server): [ OK ]
root#des [/usr/local/lib/python2.7]# 'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/opt/odoo/openerp-server", line 2, in ?
import openerp
File "/opt/odoo/openerp/__init__.py", line 47, in ?
import os
File "/usr/local/lib/python2.7/os.py", line 49, in ?
import posixpath as path
File "/usr/local/lib/python2.7/posixpath.py", line 339
slash, dot = (u'/', u'.') if isinstance(path, _unicode) else ('/', '.')
^
SyntaxError: invalid syntax
root#des [/usr/local/lib/python2.7]#
Any help will be appreciated
Thanks
Jaime
try this syntax
from «app_name».models import *
Related
Getting this error when trying to import socketio in python 2:
root#udacity:~/Desktop/CarND-Capstone-master/ros# python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socketio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/socketio/__init__.py", line 3, in <module>
from .client import Client
File "/usr/local/lib/python2.7/dist-packages/socketio/client.py", line 6, in <module>
import engineio
File "/usr/local/lib/python2.7/dist-packages/engineio/__init__.py", line 3, in <module>
from .client import Client
File "/usr/local/lib/python2.7/dist-packages/engineio/client.py", line 302
'Unexpected response from server') from None
^
SyntaxError: invalid syntax
Tried reinstalling/installing socketio and engineio, but can't seem to get it to work. I should mention that I'm running in an Ubuntu VM.
I found the answer, as shown above, it was an engineio fault. Installing it before socketio in my requirements file worked. Particularly I'm using python-socketio==4.4.0, and python-engineio==3.11.2
python-engineio==3.11.2
python-socketio==4.4.0
Reference:
https://github.com/udacity/CarND-Capstone/issues/342
Team,
I have a problem importing tensorflow if I run python from the home directory terminal. Please see below:
rkenaya#rkenaya:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/node_def_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in <module>
serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"r\n\x13ResourceHandleProto\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tB/\n\x18org.tensorflow.frameworkB\x0eResourceHandleP\x01\xf8\x01\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
>>>
However I do not get any error if I run python from python native directory. Please see below:
rkenaya#rkenaya:/usr/local/lib/python2.7/dist-packages$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>>
Note: I am using ubuntu 16.04 LTS
Any help would be highly appreciated folks.
Riyadh
so I have tested this under several different variations. I have a lab with Windows 2008 R2 servers and RHEL6 and Python2.6 installed. I am able to use ansible as means to remote into the windows server and perform a ping (I have followed all the instructions on how to do this).
I get the problem of not being able to do this with Rhel 7 and python2.7, however I am not sure that the difference in python versions is whats stopping me.
I constantly get this hostname_override error...
[alebede#linuxbox]$ klist -a
Ticket cache: FILE:/tmp/krb5cc_37575
Default principal: Admin_alebede#mydomain.bla
Valid starting Expires Service principal
02/10/2017 11:30:32 02/10/2017 21:30:32 krbtgt/mydmain.bla#mydomain.bla
renew until 02/10/2017 21:30:32
Addresses: (none)
[alebede#linuxbox]$ python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import winrm
>>> s = winrm.Session('WINDOWSBOX', auth=('admin_alebede#mydomain.bla', 'mypassword'), transport='kerberos')
>>> r = s.run_cmd('ipconfig', ['/all'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/winrm/__init__.py", line 37, in run_cmd
shell_id = self.protocol.open_shell()
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 173, in send_message
self.session = self.build_session()
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 140, in build_session
sanitize_mutual_error_response=False)
TypeError: __init__() got an unexpected keyword argument 'hostname_override'
With ansible it looks like this, the same hostname_override error:
mywinserver.mydomain.com> WINRM CONNECT: transport=ssl endpoint=https://mywinserver.mydomain.com:5986/wsman
<mywinserver.mydomain.com> WINRM CONNECTION ERROR: the specified credentials were rejected by the server
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", line 154, in _winrm_connect
self.shell_id = protocol.open_shell(codepage=65001) # UTF-8
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 190, in send_message
raise InvalidCredentialsError("the specified credentials were rejected by the server")
InvalidCredentialsError: the specified credentials were rejected by the server
mywinserver.mydomain.com | UNREACHABLE! => {
"changed": false,
"msg": "kerberos: __init__() got an unexpected keyword argument 'hostname_override', ssl: the specified credentials were rejected by the server",
"unreachable": true
}
Let me know what else I can try, also on the Windows 2008R2 server i can see that the linux box is trying to connect in the security event log. Not sure what else is going on. Again, this works in RHEL6 on 2 different windows 2008R2 servers.
Likely you have a mismatch in versions between winrm and requests-kerberos. I had the same issue when I had winrm installed via pip and requests-kerberos install via apt.
Verify that you are using a single package manager for all installations.
I have a pickle file, with
>>> with open("wikilinks.pickle", "rb") as f:
... titles, links = pickle.load(f)
...
>>> len(titles)
13421
I can load it in python3.
However, when I try to load it in python2, I get this message:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python2.7/pickle.py", line 1378, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 886, in load_proto
raise ValueError, "unsupported pickle protocol: %d" % proto
ValueError: unsupported pickle protocol: 3
So how to load it in python2?
Read in python3 and save it as python2 format
#!/usr/bin/env python3
import pickle
with open("a.pkl", "rb") as f:
w = pickle.load(f)
pickle.dump(w, open("a_py2.pkl","wb"), protocol=2)
Then you can load a_py2.pkl in python2.
The default pickling protocol used by default in Python 3 is incompatible with the protocol used by Python 2. However, if you can modify the code that produces wikilink.pickle, you can tell it to use one of the earlier protocols (0, 1, or 2) which Python 2 will understand just fine.
Be warned, though, that Python 3 strings will come up as Unicode strings in Python 2, which may be surprising in some use cases.
$ python3
Python 3.4.1 (default, May 19 2014, 17:23:49)
[GCC 4.9.0 20140507 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> pickle.dumps([1, 2, 'abc'], 2)
b'\x80\x02]q\x00(K\x01K\x02X\x03\x00\x00\x00abcq\x01e.'
>>>
$ python
Python 2.7.8 (default, Jul 1 2014, 17:30:21)
[GCC 4.9.0 20140604 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cPickle
>>> cPickle.loads('\x80\x02]q\x00(K\x01K\x02X\x03\x00\x00\x00abcq\x01e.')
[1, 2, u'abc']
I recently updated my system (OXS 10.9.1 -> 10.9.2), and my python using brew (2.7.3 -> 2.7.6).
Now I am getting very strange behaviour. One example is trying to run a test app which creates flask sockets:
jono#air:~/Workspace/sandbox $ python app.py
Traceback (most recent call last):
File "app.py", line 9, in <module>
import flask, flask_sockets, time, threading, simplejson
File "/usr/local/lib/python2.7/site-packages/flask/__init__.py", line 21, in <module>
from .app import Flask, Request, Response
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 26, in <module>
from . import json
File "/usr/local/lib/python2.7/site-packages/flask/json.py", line 25, in <module>
from itsdangerous import json as _json
ImportError: No module named itsdangerous
First thought is to update itsdangerous:
jono#air:~/Workspace/sandbox $ pip install itsdangerous --upgrade
Requirement already up-to-date: itsdangerous in /usr/local/lib/python2.7/site-packages
Cleaning up...
Checking that it installed correctly:
jono#air:~/Workspace/sandbox $ locate itsdangerous
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/PKG-INFO
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/SOURCES.txt
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/dependency_links.txt
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/installed-files.txt
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/not-zip-safe
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/top_level.txt
/usr/local/lib/python2.7/site-packages/itsdangerous.py
/usr/local/lib/python2.7/site-packages/itsdangerous.pyc
Checking my PYTHONPATH:
jono#air:~/Workspace/sandbox $ echo $PYTHONPATH
/usr/local/lib/python2.7/site-packages/
Checking that python is looking in the correct PYTHONPATH:
jono#air:~/Workspace/sandbox $ python
Python 2.7.6 (default, Mar 6 2014, 10:46:26)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import itsdangerous
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named itsdangerous
>>> import os
>>> os.getenv("PYTHONPATH")
'/usr/local/lib/python2.7/site-packages/'
>>>
I'm having similar issues with other basic packages like virtualenv too:
jono#air:~/Workspace/sandbox $ virtualenv venv
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2720, in <module>
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 588, in resolve
The `plugin_env` should be an ``Environment`` instance that contains
pkg_resources.DistributionNotFound: virtualenv==1.9.1
Is it installed?
jono#air:~/Workspace/sandbox $ pip install virtualenv --upgrade
Requirement already up-to-date: virtualenv in /usr/local/lib/python2.7/site-packages
Cleaning up...
But strangely this time python can see it:
jono#air:~/Workspace/sandbox $ python
Python 2.7.6 (default, Mar 6 2014, 10:46:26)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import virtualenv
>>> dir(virtualenv)
['ACTIVATE_BAT', 'ACTIVATE_CSH', 'ACTIVATE_FISH', 'ACTIVATE_PS', 'ACTIVATE_SH', 'ACTIVATE_THIS', 'BIG_ENDIAN', 'ConfigOptionParser', 'ConfigParser', 'DEACTIVATE_BAT', 'DISTUTILS_CFG', 'DISTUTILS_INIT', 'FAT_MAGIC', 'LC_LOAD_DYLIB', 'LITTLE_ENDIAN', 'Logger', 'MH_CIGAM', 'MH_CIGAM_64', 'MH_MAGIC', 'MH_MAGIC_64', 'OK_ABS_SCRIPTS', 'REQUIRED_FILES', 'REQUIRED_MODULES', 'SITE_PY', 'UpdatingDefaultsHelpFormatter', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_find_file', 'abiflags', 'base64', 'call_subprocess', 'change_prefix', 'codecs', 'convert', 'copy_required_modules', 'copyfile', 'copyfileordir', 'create_bootstrap_script', 'create_environment', 'default_config_file', 'default_storage_dir', 'distutils', 'errno', 'expected_exe', 'file_search_dirs', 'fileview', 'filter_install_output', 'find_wheels', 'fix_lib64', 'fix_local_scheme', 'fixup_egg_link', 'fixup_pth_and_egg_link', 'fixup_pth_file', 'fixup_scripts', 'get_installed_pythons', 'glob', 'install_activate', 'install_distutils', 'install_python', 'install_wheel', 'is_cygwin', 'is_darwin', 'is_executable', 'is_executable_file', 'is_jython', 'is_pypy', 'is_win', 'join', 'logger', 'logging', 'mach_o_change', 'main', 'majver', 'make_environment_relocatable', 'make_exe', 'make_relative_path', 'maxint', 'minver', 'mkdir', 'optparse', 'os', 'path_locations', 'py_version', 're', 'read_data', 'relative_script', 'resolve_interpreter', 'rmtree', 'shutil', 'strtobool', 'struct', 'subprocess', 'subst_path', 'sys', 'tarfile', 'tempfile', 'user_dir', 'virtualenv_version', 'writefile', 'zlib']
>>> virtualenv.is_darwin
True
>>> virtualenv.__file__
'/usr/local/lib/python2.7/site-packages/virtualenv.pyc'
>>>
Somehow, many of my packages in /usr/local/lib/python2.7/site-packages/ had root ownership. This was causing a host of issues :/
sudo pip uninstall XXX
followed by
pip install XXX
Resolved most of the issues.
Let the lesson be learnt that one should never 'sudo pip install' anything.