How can I fix this Python script? - python

I'm trying to convert a CVS repository to Git using cvs2svn and am following the directions on this page. I got to step 7 but am getting an error running git-move-refs.py:
Traceback (most recent call last):
File "../../cvs2svn-trunk/contrib/git-move-refs.py", line 23, in ?
from subprocess import Popen, PIPE, call
ImportError: No module named subprocess
For reference, this is what the script shows:
usage = 'USAGE: %prog [options]'
import sys
import optparse
from subprocess import Popen, PIPE, call
I'm not a Python expert but from browsing the web it looks like subprocess is a standard module, right? I'm using a Python installation built from source for version 2.6.3. What am I missing for this script to work?

I'm guessing that you have an old version (pre-2.4) of Python at /usr/bin/python, from your distribution, and the Python 2.6 you compiled is somewhere else (like /usr/local/bin/python). You have the Python 2.6 executable on your path before /usr/bin, so when you execute python from the command-line you get Python 2.6.
However, looking at the cvs2svn source code, git-move-refs.py's interpreter line is hard-coded to
#!/usr/bin/python
instead of #!/usr/bin/env python, which means when you run the script it uses the old Python.
As a workaround, run the script by passing it to your Python 2.6 interpreter:
user#host$ python /path/to/cvs2svn/contrib/git-move-refs.py

Related

Run Python module in another code but with an older version

I am using Python 3.10 but I want to run a Python module with Python 3.6 and use the result inside my code(that written with Python 3.10)
Please help me to solve it
thanks
Create a .py script that should be run with python3.6
Make the script prints your expected result
# script.py
import sys
print(sys.version[:6])
Use subprocess to get it
import subprocess
python3_6_result = subprocess.check_output(["python3.6", "script.py"])
print(python3_6_result) # 3.6.15

Running bash/python script with ProcessBuilder

I want to run a bash script by using ProcessBuilder. This is my xtend code:
new ProcessBuilder().inheritIO().command("/bin/bash", "-c", "./myscript.sh")
This is my bash script:
#!/bin/bash
python WebRoot/result.py
And the python code:
#! /usr/bin/env python
import rospy
from std_msgs.msg import Empty
...
The problem is that I get an error:
Traceback (most recent call last):
File "WebRoot/result.py", line 2, in <module>
import rospy
ImportError: No module named rospy
However, when I run the code manually via terminal, it works fine.
When you run it command line, you are probably getting a different environment from when it's running in your JVM. In your bash script, try pointing directly to the python version you intend to use. It's entirely possible that the JVM's env is pointing to a different version of python. Or that the environment is not fully setup.
Try to put the full path, like this, for example:
#!/bin/bash
/usr/bin/python2.7/python WebRoot/result.py

I have a problem when I try to run python command in bash

I'm trying to run this command in bash: python3 HelloServer.py (HelloServer.py is the python file I want to run). It returns
["bash: python3: command not found"][1]
and if i run the following command...
python HelloServer.py it returns
"Traceback (most recent call last):
File "HelloServer.py", line 7, in <module>
from http.server import HTTPServer, BaseHTTPRequestHandler
ImportError: No module named http.server"
this is the bash:
this is the HelloServer.py code
Based on that module, it looks like the file you're trying to run is meant for python3 which you don't seem to have installed. Easily remedied though: https://www.python.org/downloads/
There are two possibilities, first is that as indicated by Bernard you don't have installed python 3, the second is that you do have python 3 installed but you are using python 2.7
It seems you don't have python3 installed. Try which python3 in your shell (Linux). The http.server module is for python3 only. If you want to stick to python2, SimpleHTTPServer might be what you want.
I seems that you haven't python3 on your system.
You need to install python3 first.
apt-get install pyhton3
After this you could write command in python3

python3 - ImportError: No module named twython

I am using python3.
I installed twython on my MAC using pip3 command and I confirmed it was successfully installed.
When I run my python file, it comes up with:
ImportError : No module named twython
My code is as follows:
import sys
import string
import json as simplejson
from twython import Twython
I can't comment the response from #ajxs, but as additional information to his repsonse:
You can change the default python interpreter like this in your MAC terminal:
nano ~/.bash_profile
Add this to the file:
alias python=python3
exit the the bashrc file and run the following command:
source ~/.bash_profile
Now you can check the defaul python version with:
python --version
Maybe this helps you.
First thing that springs to mind is to check that you're running the script with the correct version of Python. Use python --version on the command line to check which version of Python you're executing by default. I've definitely had problems like this before when I've forgotten that my system's default version was 2.7 and I needed to use python3 to run Python 3 on the command line.

Installing IPython for Sublime Text 2's embedded Python interpreter

I am trying to install the IpythonIntegration package in sublime,
I installed in a bash shell:
the latest ipython
pyzmq
pyside
However, the sublime console still gives me an error of
Reloading plugin /home/areal/.config/sublime-text-2/Packages/User/ipython_repl.py
Traceback (most recent call last):
File "./sublime_plugin.py", line 62, in reload_plugin
File "./ipython_repl.py", line 13, in <module>
from IPython.zmq.blockingkernelmanager import BlockingKernelManager
ImportError: No module named IPython.zmq.blockingkernelmanager
EDIT:
Even a import IPython won't work.
When in python console, import IPython and import zmq work, however:
from IPython.zmq.blockingkernelmanager import BlockingKernelManager
Fails with:
ImportError: No module named zmq.blockingkernelmanager
I have 0MQ 3.2 (also tried with 2.x), and latest PyZMQ.
I am working with Python 2.7.2 on Ubuntu 11.10.
So in general I have 2 problems:
No IPython in Sublime (I assume it is because sublime works with an embedded interpreter)
No zmq module in IPython
I am not using Ubuntu, but I meet similar issue in Mac OS X.
The reason why it success in standalone python and fail in sublime text 2 is : sublime text 2 is using python 2.6 defaultly, while you standalone python is 2.7.
To solve this, in my OS X, I create a soft link from 2.7 to 2.6, something like below:
cd /Library/Frameworks/Python.framework/Versions/
sudo mv 2.6 2.6-backup
ln -s 2.7 2.6
I think you can do same thing in Ubuntu.

Categories

Resources