Is it possible to use Python 3 instead of Python 2?

I’m really happy how easy it is to put together a simple Python web-application using gomix. I’v noticed however that it still uses Python 2.7. Is it possible to switch to Python 3 somehow?

1 Like

Yes, you should be able to use python3 as the command instead of python :slight_smile:

Thanks. Unfortunately python3 does not know about the my requirements.txt.

1 Like

I got Python 3 working with requirements.txt support:

1 Like

how did you manage that?

If you follow the link above, you can click “View Code” to see how, and after that you can remix the project as a starting point for your own.

thanks! (& apologies) duh … :slight_smile:

would it be easier to point pip3 (instead of pip) to the requirements.txt file?

It might be worth a try. You’d work without a virtualenv and might shave off a few lines of code.

not that i’d now how to do that, just seemed to make sense. if i remix your project everything works but if i copy your start.sh to my project i get a permissions error when creating the virtualenv:

Exception:
2:32 PM
Traceback (most recent call last):
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
2:32 PM
    status = self.run(options, args)
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 342, in run
2:32 PM
    prefix=options.prefix_path,
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 784, in install
2:32 PM
    **kwargs
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 851, in install
2:32 PM
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
2:32 PM
    isolated=self.isolated,
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 345, in move_wheel_files
2:32 PM
    clobber(source, lib_dir, True)
2:32 PM
  File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 323, in clobber
2:32 PM
    shutil.copyfile(srcfile, destfile)
2:32 PM
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
2:32 PM
    with open(dst, 'wb') as fdst:
2:32 PM
Jump to
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/virtualenv.pyc'

I can have a look if you can link your project.

thanks!

this is it as is (py2.7) https://glitch.com/~because-iam-worthit

i swapped my start.sh for yours and i got that exception

Not sure what’s going on since I’m not too familiar with glitch, but I was able to bootstrap pip in a remix of your project with the following shell-script:

#!/bin/bash

# Exit early on errors
set -eu

# Python buffers stdout. Without this, you won't see what you "print" in the Activity Logs
export PYTHONUNBUFFERED=true

# Install Python 3 virtual env
VIRTUALENV=.data/venv

if [ ! -d $VIRTUALENV ]; then
  python3 -m venv $VIRTUALENV
fi

if [ ! -f $VIRTUALENV/bin/pip ]; then
  curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | $VIRTUALENV/bin/python
fi

# Install the requirements
$VIRTUALENV/bin/pip install -r requirements.txt

# Run a glorious Python 3 server
$VIRTUALENV/bin/python3 server.py

@href try this:

1 Like

Sorry for bumping, but do you have a Python3 version of that?

Try going to the @python glitch team

1 Like

iirc you just change python to python3 in the glitch.json or start.sh file. Some systems but not glitch’s have python-is-python3 installed which will make it so python goes to python3