How to import PubNub - pubnub

Hello I import Pubnub in my python file I already installed Pubnub in python env, it's installed just fine but when I try to be import,it's not imported in my python file, Can anybody help me
below I also attach some screenshotsenter image description here

As stated in the PubNub Python Docs:
Install pubnub using pip:
pip install 'pubnub>=7.0.0'
In your python main add:
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconfig = PNConfiguration()
pnconfig.subscribe_key = 'mySubscribeKey'
pnconfig.publish_key = 'myPublishKey'
pnconfig.user_id = "my_custom_user_id"
pubnub = PubNub(pnconfig)
Remember to always set your user_id in the pnconfig object.
Finally, add the callback listeners like in this full sample: PubNub Python Putting it together

Related

base64 library for circuitpython on SEEED Xiao ESP32-C3

I'm trying to import base64 on the SEEED Xiao ESP32-C3 which is running circuitpython version 8 beta 6. However, when I use import base64 or import ubase64 I see the error ImportError: no module named 'base64' which is the same for ubase64. The only option was to use !pip install circuitpython-base64 which does not include b32decode. I read that base64 comes with Python by default which does not seem to be the case here. Is there any workaround?
circuitpython-base64 does include b32decode! If you want to take a look at the source it is here. After running pip install circuitpython-base64, the following script should work.
import circuitpython_base64 as base64
bytes_to_encode = b"Aladdin:open sesame"
print(repr(bytes_to_encode))
base32_string = base64.b32encode(bytes_to_encode)
print(repr(base32_string))
decoded_bytes = base632.b32decode(base32_string)
print(repr(decoded_bytes))

Use pcl in ROS with python

I'm new to the ROS and i have a problem.
I'm trying to visualize a point cloud using pcl library.
At first i start my ros-realsense camera typing in a terminal "roslaunch realsense2_camera rs_camera.launch filters:=pointcloud"
Then, i have made a catkin package where i have a listener.py script where i subscribe to the realsense and i get the point cloud information that i want. So far so good!
Now i want to visualize this point cloud using the PCL library but when i run my package "rosrun pcl listener.py" i get the error
import pcl
ImportError: No module named pcl
So my question is what do i miss?
How do i import the pcl in a ros package?
Do i have to add something on the CMakeLists.txt or/and package.xml?
I include my listener.py script.
#!/usr/bin/env python
import rospy
import pcl
import ros_numpy
import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2
def callback_ptclud(ptcloud_data):
pc = ros_numpy.numpify(data)
points=np.zeros((pc.shape[0],3))
points[:,0]=pc['x']
points[:,1]=pc['y']
points[:,2]=pc['z']
p = pcl.PointCloud(np.array(points, dtype=np.float32))
def listener():
rospy.Subscriber("/camera/depth/color/points", PointCloud2, callback_ptclud)
rospy.spin()
if __name__ == '__main__':
rospy.init_node("realsense_subscriber", anonymous=True)
listener()
Thank you in advance
Any help is appreciated
About the pcl the most easiest way is to use it with C++. Its easy to install and there are a lot of documentations and examples.
About the python_pcl for some reason its not easy to install (at least for me). What i did to use it was to download the library, put it somewhere in my pc and when i want to use it in my scripts i just import the absolute path of pcl.
By downloading the python_pcl files i mean find and download the init.py, _pcl.py, _pcl.so and all the necessary files of the library.
For example in my python scripts i use:
import sys
sys.path.append('~/path_to_downloaded_pcl') "it will find the __init__.py"
import pcl

AWS Lambda python: Unable to import module 'lambda_function': No module named 'regex._regex'

I am currently working with AWS Lambda. Here is an excerpt of the code:
import pandas as pd
import re
import nltk
from stop_words import get_stop_words
stopwords = get_stop_words('en')
nltk.download('punkt')
nltk.download('wordnet')
wn = nltk.WordNetLemmatizer()
def lemmatization(txt):
text = ([wn.lemmatize(word) for word in txt])
return text
def lambda_handler(event,context):
bucket = "aaabbb"
key = "cccddd"
s3_client = boto3.client('s3')
s3_file = s3_client.get_object(Bucket=bucket, Key=key)
s3_file_data = s3_file['Body'].read()
s3_file_data = io.BytesIO(s3_file_data)
df = pd.read_csv(s3_file_data)
df['ABC'] = df['ABC'].apply(lambda x: lemmatization(x))
print(df)
However, I am always getting the error:
Unable to import module 'lambda_function': No module named 'regex._regex'
I have already imported nltk and regex packages. Could you please help me with it?
A possible solution could be that your OS uses a different version of Python (i.e. 3.6) when downloading your dependencies than your Lambda Function (i.e. 3.7). I would suggest attempting to download whatever version of Python you are using for your lambda script, and then for example if I wanted the version of Python to be 3.8 I would run the code:
pip3.8 install -r requirements.txt -t aws-lib .
I faced this problem just like you. The problem causing this error is the difference in the OS that you use and lambda function uses. When python installs a package it creates the installed files with respect to the OS you use. So when you use the deployment bundle that was created using a linux OS then it would work with lambda function.
There are many ways for a windows user to do this, but I would recommend using docker containers to install your packages.
Steps to do it:
pull python:3.8 docker image (this is the highest version supported by lambda at the time of writing this answer)
run your container with the directory with the code mounted to the container as volume.
now inside the container navigate to the mounted folder and install your required packages using pip.
come out of your container and now use these installed packages to build your bundle and deploy it on AWS lambda
ps: now when you execute your code on windows it will give an error because the packages installed are built for linux OS

Python 3: No module named zlib?

I am trying to run my Flask application with an Apache server using mod_wsgi, and it has been a bumpy road, to say the least.
It has been suggested that I should try to run my app's .wsgi file using Python to make sure it is working.
This is the contents of the file:
#!/usr/bin/python
activate_this = '/var/www/Giveaway/Giveaway/venv/bin/activate_this.py'
with open(activate_this) as f:
code = compile(f.read(), "somefile.py", 'exec')
exec(code)
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/Giveaways/")
from Giveaways import application
application.secret_key = 'Add your secret key'
However, when I run it, I get this error:
ImportError: No module named 'zlib'
And no, I am not using some homebrewed version of Python - I installed Python 3 via apt-get.
Thanks for any help.
does the contents of somefile.py include the gzip package? in which case you may have to install gzip package via pip or similar

Python 3.4 import gcm raise a SystemError: Parent module '' not loaded, cannot perform relative import

I'm trying to import gcm as following:
from . import gcm
And i get:
SystemError: Parent module '' not loaded, cannot perform relative import
I tried also called:
from gcm import GCM
by pip install python-gcm but i get the follwoing error:
module' object has no attribute 'GCM
Don't use the relative import syntax, from . import gcm. Instead, put the library where the Python interpreter can find it (via pip install python-gcm) and call from gcm import GCM in your program.
However, if you still get an error while attempting to import, you should add a comment to the project's open Python3 import issue thread on GitHub and let them know, since there still appears to be some ambiguity if this bug has been fixed yet or not.
Make it run temporarily
python-gcm depends on the requests package. Make sure it is installed. Invoke pip install requests to install it.
Download the ZIP archive of the master branch.
Extract the archive into a folder python-gcm-master.
Patch the file python-gcm-master/gcm/__init__.py. Use
import gcm
#GCM = gcm.GCM
instead of
import gcm
GCM = gcm.GCM
In this folder create a python file test.py. This file should contain example code from the python-gcm package:
from gcm.gcm import GCM
gcm = GCM(API_KEY)
data = {'param1': 'value1', 'param2': 'value2'}
# Plaintext request
reg_id = '12'
gcm.plaintext_request(registration_id=reg_id, data=data)
# JSON request
reg_ids = ['12', '34', '69']
response = gcm.json_request(registration_ids=reg_ids, data=data)
# Extra arguments
res = gcm.json_request(
registration_ids=reg_ids, data=data,
collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600
)
Run this file using python3 test.py. Be aware that the example uses from gcm.gcm import GCM instead of the default from gcm import GCM
If an gcm.gcm.GCMAuthenticationException is thrown, you can see that it is imported correctly and you need to adjust your API_KEY. Adjust the test.py file according to your needs.
Make it run permanently
As far as you tried a relative import, I think you already came across issue 65. Apparently they broke the import mechanism for python3. However, it works per default on python2, but it is buggy with python3. The issue in the issue tracker is still open.

Resources