how to activate python3 in Google-cloud-data - python-3.x

I am using Python3 for my projects. However, the Google Cloud Datalab runs with Python2.7.x by default. How do I change to Python3?

Datalab only supports Python 2 for now unfortunately.
One thing you can try is install the Pydatalab lib, which is a Jupyter extension that adds support for a number of Google Cloud Platform services to your Jupyter notebooks. That library supports Python 3.

It looks like that they support Python 3 now:
https://github.com/googledatalab/datalab/issues/902 .

Related

Is there a way to OCR images in PySpark?

I can not find an open source solution for OCRing images in PySpark. I know solutions like pytesseract exist, but not sure if they will play nicely with PySpark since the tesseract-ocr will need to be installed in the linux machines. Are there any open source OCR solutions that would play nicely with PySpark?
I could not find a pure python library. pytesseract calls a linux library called tesseract-ocr which I was able to install on a Spark cluster. You can also install this on your Spark cluster fairly easily and it works well.
Here's an answer on how to install it on Databricks. I used global init scripts to install it:
How to install Tesseract OCR on Databricks

Availability of windows version of dev_appserver.py for python3 google app-engine

Google app-engine docs say that "The dev_appserver tool does not support development of Python 3 apps on Windows" (see [here]). Yet it works with python 2.7. It is required for local testing.
Will it ever be available? And if so when?
I wish Google was clearer and more explicit about this, but I don't believe so.
With Python 3 GAE, all the GAE-specific stuff (datastore, taskqueue, etc.) has been moved to APIs and you install python libraries to use them the same way that you would interact with any third-party API.
You run your app on the command line with a local server. You should have a file similar to this:
from myapp import app
if __name__ == '__main__':
app.run(host='127.0.0.1', debug=True)
and you just run it like this
python main.py
For interacting with GAE stuff, you should have a test project and use the test project credentials when running locally.
Many people have recommended Waitress. It's not a GAE simulator but it helps with WSGI if you're on Windows and can't use Gunicorn.

How to determine google project name in python 3 appengine standard at runtime

I am doing some of the pre-work to port my python 2.7 appengine app to python 3.x. One piece that we use in our 2.7 app is detecting the project at run time, so we can set up different environments for different projects (testing, staging and production). I have not found a good way of doing this with the new python 3.x environment. Has anyone else had to do this?
What we're doing in our current app is:
from google.appengine.api import app_identity
app_identity.get_application_id()
I'm kind of hoping there is a magic environment variable or something that will indicate what I'm project I'm running on. Thanks in advance!
On App Engine Standard you have Environment variables predefined, among them you have “GAE_APPLICATION” which contains the ID of your App Engine application. You can see it on the following link:
https://cloud.google.com/appengine/docs/standard/python3/runtime#environment_variables

Python 3.5 support for Google-Contacts V3 API

I'm trying to work with the Google contacts API using Python 3.5, this presents an issue because the gdata library that is supposed to be used is not up to date for use with Python 3.5. I can use oAuth2 to grab the contact data in JSON and use that in my project, but part of the application is also adding a contact into the users contact list. I cannot find any documentation on this part, besides using the Gdata library, something I cannot do. The majority of project requires Python 3 so, switching to Python 2 would just not be something I could easily do. Is there any further documentation or a work around using the gdata library with Python 3? I'm actually very surprised that the contacts API seems so thinly supported on Python. If anyone has any further information it would be much appreciated.
For me I had to install like pip install git+https://github.com/dvska/gdata-python3 (without the egg). Since the package itself contains src dir. Otherwise import gdata would fail. (python 3.6.5 in virtual env)
GData Py3k version: pip install -e git+https://github.com/dvska/gdata-python3#egg=gdata

Python 3 support for fabric

Does fabric (http://docs.fabfile.org/en/1.7/) support Python 3 yet. As per Python 3 Wall of Superpowers it does not yet.
If not what is the best alternative if using Django 1.5 with Python 3.
Current advice
It seems there is already official support for Python 3.4+ in Fabric v2+ and I guess it should be preferred although there may be some incompatible changes. So in an ideal world, nobody should have this problem anymore :)
pip3 install -U "fabric>2.0"
Maintained old API in Python 3
Because some people were happy with the old API of the Fabric, there is a maintained fork supporting Python 3 called fab-classic. See also discussion in the Github issue Recreating the Fabric 1 API in Fabric 2?
The previous advice
There is Python3 port of Fabric named Fabric3 which supports Python 2.7 and 3.4+ (dropped support for Python <2.7). I use it some time as a replacement and it works for me without any issues.
pip3 install fabric3
Current Answer which has already been done by #miso.belica
pip install -U "fabric>2.0.0"
OLD Answer (as of 2013)
From the docs:
Please note that all documentation is currently written with Python
2.5 users in mind, but with an eye for eventual Python 3.x compatibility
Or to be more specific:
eventual Python 3.x compatibility
It looks like Python3 support for fabric is a little sticky and depends upon another open source library, paramiko being compatible with python3. As of now, the master version supports python 3.
It might be worth messing around with and then building your fabric instance on top of that instead of getting it from pip.
You could also create a separate python2.7 virtualenv just for fabric:
sudo virtualenv --no-site-packages -p /usr/bin/python fabric-env
source /var/www/APPNAME/fabric-env/bin/activate
sudo /var/www/APPNAME/fabric-env/bin/pip install fabric
deactivate
Then:
/var/www/APPNAME/fabric-env/bin/fab -f /var/www/APPNAME/fabfile.py FAB_COMMAND
It seems that Fabric is going through a rewrite and that Fabric 2.0 will be python 3.x compatible. At least this is what I read between the line of the roadmap below. However, I cannot find the Fabric 2.0 repository or branch, so, hard to fully confirm.
http://www.fabfile.org/roadmap.html
For those looking for a supported version of Fabric 1.x, there's a fork which is maintained:
https://github.com/ploxiln/fab-classic
I recommend using it in case you don't want to rewrite all the existing code. And it works with Python 3.7.
We've switched from fabric3==1.14.post1 to fab-classic==1.15.2 without any problems.
It is actually possible to get Fabric to work with Python 3. You can see how I did it in this gist.
In the comments above, #rnevius suggests that invoke is meant as a successor of Fabric 1.x, however that is not completely correct. From the invoke docs:
Thus, Invoke was created to focus exclusively on local and abstract
concerns, leaving Fabric 2.x concerned only with servers and
network commands.
It thus seems that Fabric 2.x will be built on top of invoke. Hopefully, Fabric 2.x will be available soon, so Python2 can die as quickly as possible.
By this day "fabric 2" is awailable to work with python 3+.
"fabric 3" is unofficial fork.
To install "fabric 2" from https://pypi.org/project/Fabric/ :
pip install Fabric

Resources