Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i make pyinvoke use python3?

This question is similar to this one but not quite the same.

I have python2.7 and python3.5 installed. I can run scripts using either of them from the command line. My current default "python" is python2.

I have a python3 script using pyinvoke that i need to run, which is typically run using the command invoke <task> from the command line. Even when i set up a virtual environment that uses python3, invoke still uses python2.

I assume there is something i am missing about virtual environments?

The only work-around i have for this right now is to only install pyinvoke for python3. Then it will run under python3.

Does someone know how to set this up to work with virtual environments?

like image 628
Nicholas Tulach Avatar asked Nov 05 '15 14:11

Nicholas Tulach


1 Answers

I'd guess you have installed invoke globally, outside of all virtualenvs.

If so, a fix would be:

#!/usr/bin/bash
# Remove global invoke, at a fresh terminal or after deactivate
$ pip uninstall invoke

To test it, add to Invoke's tasks.py file:

import sys
print(sys.version_info)

Then at a Terminal check we get Python 3.x:

#!/usr/bin/bash
$ mkvirtualenv myproject_py3 --python=$(which python3)
(myproject_py3)$ pip install invoke
(myproject_py3)$ invoke --list
sys.version_info(major=3, minor=5, micro=0, releaselevel='final', serial=0)
No tasks found in collection 'tasks'!
like image 61
pzrq Avatar answered Nov 01 '22 02:11

pzrq