I'm trying to use the Python YouTube Data API Python script that allows to upload a video: https://developers.google.com/youtube/v3/guides/uploading_a_video#Sample_Code. Note that it's compatible Python 2.x, not 3.X. So I've updated its code by replacing the first import ( import httplib ) by this import: import http.client .
When I run this script, the following error is shown:
Traceback (most recent call last):
File "/home/xzerzxez/pycharm_projects/zerde/upload_video.py", line 3, in
import http.client
ImportError: No module named http.client
Process finished with exit code 0
PyCharm's used environment: my Ubuntu's one
Python version: /usr/bin/python3.6
Pertinent packages installed: httplib2, request, requests
Available packages to install: micropython-http.client, pycopy-http.client, yieldfrom.http.client
How to solve this problem?
Edit: of course I also made other littles changes to the code to make it compatible Python 3.X, but it's off-topic :-) .
Solved by changing the shebang to #!/usr/bin/python3
Related
I am new to ROS,
I have a problem when I import rospy into my script file example.py and run it: It says:
Traceback (most recent call last):
File "/home/nagarjunv/hk_ws/src/rvo/src/example.py", line 4, in <module>
import rospy
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
from .client import spin, myargv, init_node, \
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in <module>
import roslib
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 50, in <module>
from roslib.launcher import load_manifest # noqa: F401
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/launcher.py", line 42, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg'
I am importing the following into my script file:The line 4 is rospy
#!/usr/bin/env python3
import sys
import rospy
THis is my CmakeLists:
cmake_minimum_required(VERSION 3.0.2)
project(rvo)
find_package(catkin REQUIRED COMPONENTS
rospy
std_msgs
message_generation
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES rvo
CATKIN_DEPENDS rospy std_msgs
# DEPENDS system_lib
)
include_directories(
# include
${catkin_INCLUDE_DIRS}
)
This is my package xml:
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>message_generation</build_export_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>message_runtime</exec_depend>
I specify both in CMakelists and Package XML 'rospy' and importing it. I also checked my ros has rospy package available. BUt, I dont understand why I am having trouble running my script file?
rosrun rvo example.py
I will be glad to provide more details about this error. Can any please let me know the solution to this problem?
Try to change the shebang (line 1) according to the python version your ROS distro works with.
For melodic or earlier: #!/usr/bin/env python2
For noetic or later: #!/usr/bin/env python3
Depending on your ROS version and respectively the one of rospkg you may need to stick to python 2.x or 3.x.
Your script is calling python3 interpreter
#!/usr/bin/env python3
but you can clearly see in the error log that a different version is used by your installation:
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/init.py",
line 49, in
from .client import spin, myargv, init_node, \
If you want to use Python 3 for a ROS installation that is based on Python 2.7 you need to build everything from scratch but even then the chances for success are pretty slim.
Here are some possible solution:
If you want to use Python 3, see here. According to this article ROS Noetic is targeting only Python 3.
If you don't want to upgrade, you need to stick to Python 2.7.
If the version of Python is of no concern, just adapt your script to use the one your ROS installation is depending on.
I am using and importing ConfigParaser
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('Config.properties')
timeout_val=config.get('Section', 'commandtimeout')
and install it using,
pip install ConfigParser
While running the python script getting below mention error.
Traceback (most recent call last):
File "system_offline.py", line 41, in <module>
import ConfigParser
ImportError: No module named 'ConfigParser'
Now, my question is if run the same program using python 2.7 at the same system, above import statement works with out issue.
Wondering what needs to be done for this program to run with python3?
Edit: While using python 2.7 it is working but with python3, i am getting above mention error.
The ConfigParser module was renamed to configparser in Python 3.0.
If you are using python 3, this will work, the module was renamed
import configparser
config = configparser.RawConfigParser()
I previously had Python 2.7 installed and was making calls like this:
api = jsonrpclib.Server('my host')
api.someFunctionCall()
I then upgraded to Python 3.5.2 and now when I run the code above, I'm receiving this message:
Traceback (most recent call last):
File "C:\login\login.py", line 1, in <module>
import jsonrpclib
File "C:\Python3.5.2\lib\site-packages\jsonrpclib\__init__.py", line 5, in <module>
from jsonrpclib.jsonrpc import Server, MultiCall, Fault
ImportError: No module named 'xmlrpclib'
I checked my installation and I do indeed have the xmlrpc lib:
c:\Python3.5.2\Lib\xmlrpc
What am I doing wrong?
Python 3.x has relocated the xmlrpclib module. Per the Python 2.7 xmlrpclib documentation:
"The xmlrpclib module has been renamed to xmlrpc.client in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3."
It looks like the author of jsonrpclib has an open issue for Python 3 support, but hasn't responded or taken pull requests in a year. You may want to give the jsonrpclib-pelix fork a look for Python 3 support.
i've installed python client library for Fusion Tables (here) with all dependencies. But if i try to run oauth_example.py, it aswers me
Traceback (most recent call last): File "./oauth_example.py", line
13, in
from authorization.oauth import OAuth ImportError: No module named authorization.oauth
my python version is 2.7.2+ running on Ubuntu 11.10
and yolk -l
oauth2 - 1.5.211 - active development (/usr/local/lib/python2.7/dist-packages/oauth2-1.5.211-py2.7.egg)
What's wrong?
It seems like you are running the script from the src/samples directory. Try copying the script up one directory and run from the src directory where it can find the authorization/oauth.py module. Or you could include something like this in the top of your python script:
import sys
sys.path.append( '/home/src/python_modules/fusion-tables-client/src')
I am trying to import NLTK in my python code and I get this error:
Traceback (most recent call last):
File "/home/afs/NetBeansProjects/NER/getNE_followers.py", line 7, in <module>
import nltk
ImportError: No module named nltk
I am using NetBeans: 6.7.1, Python 2.6 NLTK.
My NLTK module is installed in /usr/local/lib/python2.6/dist-packages/nltk/ and I have added this in Python paths in Netbeans.
What am I missing here?
Thanks in advance.
You might have default python installation on /usr/bin/python. So, In Netbeans preference, try to set python interpreter to /usr/local/bin/python instead of /usr/bin/python
Rectified the problem. I had included the nltk path in the Netbeans global settings but the project was still using Jython 2.5 as its Python platform so the global settings never affected the project.