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


#1

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?


#2

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


#3

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


#4

I got Python 3 working with requirements.txt support:


#5

how did you manage that?


#6

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.


#7

thanks! (& apologies) duh … :slight_smile:


#9

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


#10

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


#11

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'

#12

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


#13

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


#14

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