0

I have installed 3to2-1.1.1 on my system (found here), cd'd to the directory of my test file (a simple "Hello, world!" program written in 3 syntax) Typed into my command prompt:

python 3to2 HelloWorld.py

With the following output:

python: can't open file '3to2': [Errno 2] No such file or directory

I attempted to change the directory name/path, but after looking over this post, I'm convinced it may be a dependency issue?

I have raised an issue on the creator's repo, and searched endlessly on the interwebs, but seem to be the only person in the world experiencing this issue.

I have tried uninstalling and re-installing just...so many ways. Any and all help appreciated - even if you just tell me it's operator error.

Extra notes:

  • I am running Python 2.7 (but also tried installing and running this with 3)
  • I am using a Windows cmd
Community
  • 1
  • 1
  • Have you tried passing the complete path of 3to2 to Python? Like this: `python \path\to\3to2 HelloWorld.py` – Quirk Dec 15 '15 at 09:17
  • @KevinGuan and Quirk, I have even tried moving my file into the 3to2 folder, i.e. - `C:\Users\username\3to2-1.1.1>python 3to2 -w HelloWorld.py` To no avail... Also installed in various ways (build, setup install, pip, etc). Edit - markdown formatting – RobotLauren Dec 15 '15 at 21:09
  • Okay, this may sound silly, but does the file `3to2` even exist? Additionally you could try renaming `3to2` to `3to2.py` and then running. You are basically getting an ENOENT error (I/O error). That would either mean a problem with PYTHONPATH, PATH or the file. – Quirk Dec 16 '15 at 03:43

3 Answers3

1

Windows cannot take care of shebangs. The default association in Windows is through file extensions. However, the file 3to2 does not come with a .py extension (only a shebang). As a result Windows is usually unable to determine what to do with the file.

OP discussed the following use cases:

  • python 3to2 <arg-file>. This doesn't work for me in a pip install. Python throws an internal ENOENT (I/O) error. This use case is discarded.
  • 3to2 <arg-file>. Doesn't work either. This is because Windows doesn't know how to execute this file. Funnily enough Windows cannot find the file even though its location is in the system PATH. Calling where gives negative results. Windows is not able to handle filenames without extensions, somehow.
  • Rename 3to2 to 3to2.py (in %PYTHON_INSTALL_DIRECTORY%\Scripts\) since it really is a python source file. Python on Windows is set up to handle .py file by default. The location of the file is in the system PATH. Try calling 3to2.py <arg-file>. This works!
  • Returning to the first case: After renaming, try calling python 3to2.py <arg-file>. Still doesn't work. Python throws an ENOENT error.

In conclusion, renaming the file 3to2.py is a hack that works. The dependent programs might not work.


Don't give up just yet!

So why did calling 3to2.py through Python fail? The answer is simple. Python only calls what you give it. When you specify a relative path, it will only look in the current working directory of the program and no more. When you give an absolute path, Python does the needful.


NOTES:

  • I only installed the package through pip only. I did not test through any other methods.
  • I tested this on a Windows 7 SP1 system. Newer versions may have better filesystem support.
Quirk
  • 1,305
  • 4
  • 15
  • 29
0

I tried install it via pip on my Linux, it works out-of-the-box.

However, you could just use it like 2to3. So type 3to2 -w HelloWorld.py in cmd maybe works. If cmd can't find the path of 3to2, then you need to find it manually.

kevin@Arch ~> cat 1.py 
print('Hello')
var = input('text')


kevin@Arch ~> 3to2 1.py
RefactoringTool: Skipping optional fixer: collections
RefactoringTool: Skipping optional fixer: int
RefactoringTool: Skipping optional fixer: memoryview
RefactoringTool: Skipping optional fixer: printfunction
RefactoringTool: Skipping optional fixer: unittest
RefactoringTool: Refactored 1.py
b'--- 1.py\t(original)'
b'+++ 1.py\t(refactored)'
b'@@ -1,2 +1,2 @@'
b"-print('Hello')"
b"-var = input('text')"
b"+print u'Hello'"
b"+var = raw_input(u'text')"
RefactoringTool: Files that need to be modified:
RefactoringTool: 1.py


kevin@Arch ~> 3to2 -w 1.py
RefactoringTool: Skipping optional fixer: collections
RefactoringTool: Skipping optional fixer: int
RefactoringTool: Skipping optional fixer: memoryview
RefactoringTool: Skipping optional fixer: printfunction
RefactoringTool: Skipping optional fixer: unittest
RefactoringTool: Refactored 1.py
b'--- 1.py\t(original)'
b'+++ 1.py\t(refactored)'
b'@@ -1,2 +1,2 @@'
b"-print('Hello')"
b"-var = input('text')"
b"+print u'Hello'"
b"+var = raw_input(u'text')"
RefactoringTool: Files that were modified:
RefactoringTool: 1.py


kevin@Arch ~> cat 1.py 
print u'Hello'
var = raw_input(u'text')
kevin@Arch ~> 
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
  • Unfortunately, this seems to be the case. It doesn't appear anyone is able to replicate my issue, which is making me feel like a crazy person! – RobotLauren Dec 15 '15 at 21:17
  • @RobotLauren: What's the error are you getting when you running `C:\Users\username\3to2-1.1.1>python 3to2 -w HelloWorld.py`? – Remi Guan Dec 15 '15 at 21:36
0

After installing on another system, I have not been able to replicate the issue. this makes me believe that something is wrong on my side of things. I will update here if I ever figure it out.