Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimporter can't find file on Windows 10 #75

Closed
davidcsisk opened this issue Nov 17, 2022 · 12 comments
Closed

nimporter can't find file on Windows 10 #75

davidcsisk opened this issue Nov 17, 2022 · 12 comments

Comments

@davidcsisk
Copy link

Here is a working example to reproduce the problem:

C:\Users\dave.sisk\math_speedup_example>type pmath.py
def fib(n):
if n == 0:
return 0
elif n < 3:
return 1
return fib(n - 1) + fib(n - 2)

C:\Users\dave.sisk\math_speedup_example>type nmath.nim
import nimpy

proc fib(n: int): int {.exportpy.} =
if n == 0:
return 0
elif n < 3:
return 1
return fib(n-1) + fib(n-2)

C:\Users\dave.sisk\math_speedup_example>type main.py
import nimporter
from time import perf_counter
import nmath # Nim imports!
import pmath
print('Measuring Python...')
start_py = perf_counter()
for i in range(0, 40):
print(pmath.fib(i), end=" ")
end_py = perf_counter()

print('\n\nMeasuring Nim...')
start_nim = perf_counter()
for i in range(0, 40):
print(nmath.fib(i), end=" ")
end_nim = perf_counter()

print('\n---------')
print('Python Elapsed: {:.2f}'.format(end_py - start_py))
print('Nim Elapsed: {:.2f}'.format(end_nim - start_nim))

C:\Users\dave.sisk\math_speedup_example>python main.py
Traceback (most recent call last):
File "C:\Users\dave.sisk\math_speedup_example\main.py", line 3, in
import nmath # Nim imports!
File "", line 1027, in _find_and_load
File "", line 1002, in _find_and_load_unlocked
File "", line 945, in _find_spec
File "C:\Users\dave.sisk\AppData\Local\Programs\Python\Python310\lib\site-packages\nimporter.py", line 1269, in find_spec
return Nimporter.import_nim_code(fullname, path, library=False)
File "C:\Users\dave.sisk\AppData\Local\Programs\Python\Python310\lib\site-packages\nimporter.py", line 944, in import_nim_code
NimCompiler.compile_nim_code(
File "C:\Users\dave.sisk\AppData\Local\Programs\Python\Python310\lib\site-packages\nimporter.py", line 705, in compile_nim_code
cls.check_compile_errors(errors, library, nim_args, output, tmp_cwd, warnings)
File "C:\Users\dave.sisk\AppData\Local\Programs\Python\Python310\lib\site-packages\nimporter.py", line 492, in check_compile_errors
raise NimCompileException(errors[0])
nimporter.NimCompileException: Error: unhandled exception: The system cannot find the file specified.

@davidcsisk
Copy link
Author

This works beautifully on Linux, but returns the "system cannot find the file specified" error on Windows 10. I've tried it on 2 different Windows 10 laptops, so I don't think it's anything specific to the laptop setup.

@Pebaz
Copy link
Owner

Pebaz commented Nov 18, 2022

Hi @davidcsisk , can you confirm what C compilers you have installed along with arch info?
Also, please provide Nim version (and arch), Nimble version, Choosenim version, and Python version (and arch)

@davidcsisk
Copy link
Author

Hi @Pebaz ...please let me know if there's any other info you need, or commands I should run to gather info to post.

C:\Users\david>nim --version
Nim Compiler Version 1.6.6 [Windows: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release

The only C compiler is the default mingw64.7z that's installed with nim, which works fine for nim-only apps.

@Pebaz
Copy link
Owner

Pebaz commented Nov 29, 2022

Hi @davidcsisk , I think this error occurs when the compilers do not match.

Can you confirm if you are using any of these:

  1. Python x64 MSVC + MSVC x64
  2. Python x32 MSVC + MSVC x32
  3. Python x64 MingW + MingW x64
  4. Python x32 MingW + MingW x32

My guess in this case is that Python was compiled for MSVC but Nim tries to use MingW (incompatible compilers). You can make sure by doing: python --version and it will say (MSC) instead of MSVC for some reason but MSC means "MSVC". If Python uses MSVC you won't be able to use MingW. You could install a MingW version of Python or install MSVC so that Nim (and therefore Nimporter) will use MSVC instead of MingW.

Let me know how it goes 🙂

@scrazzz
Copy link

scrazzz commented Dec 8, 2022

Hello, I'm facing this same issue. I'm not an expert on these MSVC/MingW that you're talking about

I quite did not understand this:

You could install a MingW version of Python or install MSVC ...

Are you saying that there's an MSVC version of Python? If so, how can i download it? Because I don't see anything mentioned about MSC or MSVC in python.org website.

@Pebaz
Copy link
Owner

Pebaz commented Dec 8, 2022

Hi @scrazzz, no worries, the goal here is to make the C compiler used to compile Python match the C compiler used to compile the C output from Nim.

For instance, if your python --version mentions "MSC", you will have to have Microsoft Visual C++ compiler installed on your system so that the Nim compiler can auto discover it and use it to ultimately build your Nim module.

@scrazzz
Copy link

scrazzz commented Dec 11, 2022

@Pebaz Thanks for the quick reply!

I do have Microsoft Visual C++ compiler installed. What's the next step?
image

Additional:
python
image

@davidcsisk
Copy link
Author

davidcsisk commented Dec 19, 2022

Hi...I'm not sure I fully understand the question. @Pebaz , here's my output:

C:\Users\david>python --version
Python 3.9.8

No MSVC mentioned. Does this get you what you needed? If not, please post the commands that you want me to run to display the relevant info, and I'll be more than happy to do that.

Thanks and regards,
Dave

@scrazzz
Copy link

scrazzz commented Dec 20, 2022

@davidcsisk python --version won't output the required info. Just open the Python REPL by running python in your cmd application.

@mukherjee
Copy link

@davidcsisk python --version won't output the required info. Just open the Python REPL by running python in your cmd application.

@davidcsisk As scrazzz mention python --version won't work. The correct command is actually:
python -VV

@Pebaz
Copy link
Owner

Pebaz commented Dec 28, 2022

Shoot sorry, my bad yeah opening the prompt is usually how I check that (made a bad guess). Thanks @mukherjee for the alternate way of checking. @davidcsisk have you had an opportunity to run that command?

We should be able to get to the bottom of this, I’ve seen this sort of issue happen a lot during project setup but let’s figure it out 😀

@Pebaz
Copy link
Owner

Pebaz commented Jul 26, 2023

Closing this for now but if anyone still needs help with dev env setup let me know.

@Pebaz Pebaz closed this as completed Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants