Automatic migration to Nix broke my previously working Python project

**Description:
I went to modify my replit project and was notified that the project was automatically migrating to Nix. After the migration my replit no longer runs and throws build errors. It was previously running with 0 issues.

**Expected behavior:
my previously working replit would still work after the forced, automatic migration to Nix.

**Actual behavior: replit project no longer works and returns the following error:

$ python3 Main.py
Traceback (most recent call last):
  File "/home/runner/League-Level-2-Games/Main.py", line 5, in <module>
    import tkinter as tk
  File "/nix/store/cgxc3jz7idrb1wnb2lard9rvcx6aw2si-python3-3.9.6/lib/python3.9/tkinter/__init__.py", line 37, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
exit status 1

**Steps to reproduce:
Run the replit

Bug appears at this link:
https://replit.com/@DanielCommins/League-Level-2-Games

Browser/OS/Device:
Chrome

Hi @DanielCommins ,welcome to the forums! If you are trying to install this module, enter pip install _tkinter into thw the Shell. But before that, is the _ part of the liibrary name?

1 Like

Things prefixed with a single underscore are usually internal parts of packages, and it’s probably best to try reinstalling tkinter all together.

2 Likes

@DanielCommins then do pip install tkinter

1 Like

That should have no effect since tkinter is already installed, try pip install --force-reinstall tkinter.

1 Like

Thank you for the replies, but I get the following error when trying to install tkinter from the command line:

~/League-Level-2-Games$ pip install --force-reinstall tkinter
ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none)
ERROR: No matching distribution found for tkinter
WARNING: You are using pip version 21.1.3; however, version 23.1.2 is available.
You should consider upgrading via the '/nix/store/cgxc3jz7idrb1wnb2lard9rvcx6aw2si-python3-3.9.6/bin/python3.9 -m pip install --upgrade pip' command.

I never had to do a tkinter install before and I’m wondering why I have to do it now.

Is there a way to rollback to the previous setup environment because this new one just breaks my code.

Reading some python docs, it sounds like tkinter should be a default install, and if it’s missing, I’d recommend trying your code in a new Repl and seeing if that resolves your issue.

1 Like

Thank you for the reply. I will attempt to solve this solution myself and will update this thread when I do.

1 Like

Try running curl https://pythonify.util.repl.co/recreate_python3_venv.sh | bash in the shell of the affected Repl. This will regenerate your Repl’s virtual environment.

2 Likes

Thank you for the suggestion. Inputting that line into the console I am getting this error:

~/League-Level-2-Games$ curl https://pythonify.util.repl.co/recreate_python3_venv.sh | bash  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1675  100  1675    0     0   6860      0 --:--:-- --:--:-- --:--:--  6864
PYTHONBIN not set. Please make sure it's set in your replit.nix file and try again.

Here is the content my replit.nit file (I never modified this file):

{ pkgs, legacyPolygott }: {
	deps = [
		pkgs.bashInteractive
	] ++ legacyPolygott;
}
1 Like

update
After setting the PYTHONBIN environment variable, the script now throws the following error in the console:

+ ./venv/bin/pip install git+https://github.com/replit/pip.git@main
bash: line 25: ./venv/bin/pip: No such file or directory
1 Like

I fixed up some of the configuration files in your Repl and everything is working now.

3 Likes

@IroncladDev thank you. Where is the documentation for the .nix configuration file? Seems like magic.

https://docs.replit.com/programming-ide/nix-on-replit
For more complex config, you’d find these useful:

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.