-2

I have a rather large chunk of code written in Python 2.7. My end goal is to have working versions in both Python 2 and 3, both install-able via pip and available on GitHub. What are the standard practices for this?

What I've done for mypackage

  1. Ran the 2to3 package which gives me two separate versions of the code (Python 2.7 and 3.4)
  2. Took the convention that new features will be added to 3.4 but not 2.7, though bug fixes will be pushed to 2.7
  3. Created setup.py scrips for both
  4. Uploaded to pip with Python 3.4 = mypackage version 1.0 and Python 2.7 = mypackage version 0.9.
  5. Uploaded the 3.4 version to GitHub but added a folder python27 where I included the Python 2.7 code

So now you can pip install the 3.4 and 2.7 versions, respectively, with

> pip install mypackage
> pip install "mypackage < 1.0"

This all seems convoluted. Questions:

  • What is the standard way to do this?
  • Do I really need two separate versions of the code? I was a little hesitant to use six for dependency reasons a few years down the line.
  • Is pip smart enough to download the correct Python version depending on which Python version it is tied to?
  • How does one handle this on GitHub? The two versions of the code makes this difficult.
Sal
  • 1,653
  • 6
  • 23
  • 36
  • This sort of question is too broad and opinion based for SO, take a look at http://stackoverflow.com/help/how-to-ask – pvg Mar 24 '17 at 13:47
  • @pvg How is this opinion based? Many packages exist that are compatible across Python 2 and 3. How do they handle distributing and maintaining their code? – Sal Mar 24 '17 at 13:49
  • did you take a look at the docs? SO is for specific questions, this is definitely broad, multiple-questions and some of it is very much opinion based i.e. how to handle it on github. Your best bet is to perhaps start with a 2 and 3 compatible package, see how it works and then come back with specific problems you have. Or do other research. But again, review the SO docs for what kind of questions fit SO. This one, in it's current form, does not. – pvg Mar 24 '17 at 13:53

1 Answers1

0

No. If you have python 2 and 3 in same environment, you need use pip2 or pip2.7 for python2 and pip3 or pip for python3

Or call pip as a module in each environment

  • py -3.4 -m pip install mypackage
  • py -2.7 -m pip install mypackage
GeoStoneMarten
  • 533
  • 1
  • 7
  • 19