Cassandra: File "cqlsh", line 95 except ImportError, e:
Question:
I am having trouble getting Cassandra up and running.
I have downloaded Cassandra 2.0.1 and Python 3.3.2.
Upon starting the CLI for cassandra I get an error:
C:DevApacheCassandraapache-cassandra-2.0.1bin>python cqlsh
File "cqlsh", line 95
except ImportError, e:
^
SyntaxError: invalid syntax
Any suggestions? I am going to downgrade python to 2.7 and see if that fixes my issue.
Thanks!
Answers:
The version of Cassandra that you are using is only compatible with Python 2.x.
The following syntax:
except ImportError, e:
was deprecated in Python 2.7 and removed in Python 3.x. Nowadays, you use the as
keyword:
except ImportError as e:
This means that you need to either downgrade to Python 2.x or get a version of Cassandra that is compatible with Python 3.x.
If anybody still looking for an answer, the best method is provided in the comment in the above answer by @heroin i.e. in the cqlsh file, change the header from current python3 interpreter to a python2 interpreter.
e.g.
Old
#!/usr/bin/python3
Modified
#!/usr/bin/python2
Check the path and name of your python2 interpreter and replace above. Now cqlsh will use python2 and run without any issue.
You should install python 2 and add it to your environment variable as stated above
py -2 -V
(verify that you have python 2 installed)
py -2 -m cqlsh
(from your Cassandra bin folder.)
- View image here.
I am not an expert but I can share what worked best for me without worrying about downgrading python to version 2 for the entire system.
- Install Anaconda
- Go to the environment tab at the right column
- At the bottom there is an option to create.
- For the packages of python please select 2.7. Name anything you want and then click create
- Now you can click on the environment you have created and open terminal for it
- Finally run command of cqlsh.
Everything should be working fine now!
In Windows 10 this worked for me. For starters please note that I had both Python 3 and Python 2 installed in my computer prior to encountering this error
Step 1
Go to folder C:UsersUSERAppDataLocalProgramsPythonPython3X-XX and rename your Python.exe to Python3.exe (The 3X-XX represent whichever Python3 version you have installed & the UsersUSER would be your computer’s user account)
Step 2
Go to folder C:UsersUSERAppDataLocalProgramsPythonPython3X-XXScripts and rename your pip.exe to pip3X.exe (use the same 3X which you have in the path)
Step 3
Go to your Python 2 folder (mine was at C:Python27) and make sure that you have a exe file called python.exe
Step 4
Now go to your Environment Variables (Lower Right Button) under System Properties > Advance Tab. Once inside, double click the path under the System variables section. This will open up the list of paths that are in your system. Add both Python paths by clicking new and then browse (selecting first (C:Python27) or whatever you Python 2 path is) and then by adding the Python 3 Path (C:UsersUSERAppDataLocalProgramsPythonPython3X-XX).
Hit Ok on all screens and try running CQLSH or CQLSH 192.168…. (whatever the IP is of your seed node) via cmd and it should work!
I am having trouble getting Cassandra up and running.
I have downloaded Cassandra 2.0.1 and Python 3.3.2.
Upon starting the CLI for cassandra I get an error:
C:DevApacheCassandraapache-cassandra-2.0.1bin>python cqlsh
File "cqlsh", line 95
except ImportError, e:
^
SyntaxError: invalid syntax
Any suggestions? I am going to downgrade python to 2.7 and see if that fixes my issue.
Thanks!
The version of Cassandra that you are using is only compatible with Python 2.x.
The following syntax:
except ImportError, e:
was deprecated in Python 2.7 and removed in Python 3.x. Nowadays, you use the as
keyword:
except ImportError as e:
This means that you need to either downgrade to Python 2.x or get a version of Cassandra that is compatible with Python 3.x.
If anybody still looking for an answer, the best method is provided in the comment in the above answer by @heroin i.e. in the cqlsh file, change the header from current python3 interpreter to a python2 interpreter.
e.g.
Old
#!/usr/bin/python3
Modified
#!/usr/bin/python2
Check the path and name of your python2 interpreter and replace above. Now cqlsh will use python2 and run without any issue.
You should install python 2 and add it to your environment variable as stated above
py -2 -V
(verify that you have python 2 installed)py -2 -m cqlsh
(from your Cassandra bin folder.)- View image here.
I am not an expert but I can share what worked best for me without worrying about downgrading python to version 2 for the entire system.
- Install Anaconda
- Go to the environment tab at the right column
- At the bottom there is an option to create.
- For the packages of python please select 2.7. Name anything you want and then click create
- Now you can click on the environment you have created and open terminal for it
- Finally run command of cqlsh.
Everything should be working fine now!
In Windows 10 this worked for me. For starters please note that I had both Python 3 and Python 2 installed in my computer prior to encountering this error
Step 1
Go to folder C:UsersUSERAppDataLocalProgramsPythonPython3X-XX and rename your Python.exe to Python3.exe (The 3X-XX represent whichever Python3 version you have installed & the UsersUSER would be your computer’s user account)
Step 2
Go to folder C:UsersUSERAppDataLocalProgramsPythonPython3X-XXScripts and rename your pip.exe to pip3X.exe (use the same 3X which you have in the path)
Step 3
Go to your Python 2 folder (mine was at C:Python27) and make sure that you have a exe file called python.exe
Step 4
Now go to your Environment Variables (Lower Right Button) under System Properties > Advance Tab. Once inside, double click the path under the System variables section. This will open up the list of paths that are in your system. Add both Python paths by clicking new and then browse (selecting first (C:Python27) or whatever you Python 2 path is) and then by adding the Python 3 Path (C:UsersUSERAppDataLocalProgramsPythonPython3X-XX).
Hit Ok on all screens and try running CQLSH or CQLSH 192.168…. (whatever the IP is of your seed node) via cmd and it should work!