Search code examples
pythonpipcurses

python curses module for windows can't install


i try to install curses module on windows and it ends with this error

picture:https://i.sstatic.net/fbKCJ.png


Solution

  • You can't install windows curses with 3.10 yet. It is supported on 3.9. I don't know when it will be supported for 3.10, so your best option for now is just to install 3.9.

    You can make a virtual environment with python 3.9 for any projects that need to use curses. A virtual environment makes a copy of your python interpreter and installs it into a directory of your choice. You use this by "activating" the virtual environment, and as long as you're inside that environment, anything you install will be contained by this copied installation.

    This allows you to run different versions of python, and it also allows you to install packages that you don't want cluttering up your main installation. It's a good idea to use this for all projects that are going to need packages outside of the standard library (anything that you pip install).

    To make a virtual environment with your default interpreter, type:

    python -m venv <envname> where <envname> is whatever you want the environments directory to be called. This is usually env.

    So python -m venv env would install a fresh copy of your python 3.10 to a folder called env inside your current directory.

    You activate this by typing .\<envname>\scripts\activate You'll then get a prompt that has (<envname>) in front of it, which will let you know you're in that environment.

    You can leave that environment by typing deactivate.

    In order to use a different version, you have to run venv with the interpreter you want to use on the project. So if you wanted to use python 3.9, it would be something like

    "C:\Program Files\Python39\python.exe" -m venv env depending on where you installed python 3.9. The directory I used is usually the default directory when installing for all users.

    To more easily work with other versions on windows, I make batch files for each one and put them in a utils folder that's on my system path. (I'll explain how to add a folder to the system path at the bottom if you don't know.)

    So make a file called python39.bat, and into that, put "C:\Program Files\Python39\python.exe" %*. (Or wherever the installation is. %* just expands other arguments so you can use it exactly like you would the other executable.

    That way you can create a new python 3.9 virtual environment with python39 -m venv env (along with any other arguments you want) instead of typing out the full path.

    You can also use --prompt to change the name displayed by your virtual environment instead of changing the name of the folder. This is useful for making it shorter or just keeping things straight when you're using a bunch of environments for different projects. (Using the same folder name allows you have something that doesn't change into your standard ignore files.)

    So anyway, here's an example of the full process after you install python 3.9.

    1. Go to your project directory or wherever you'd like to install the environment.
    2. type "C:\Program Files\Python39\python.exe" -m venv env (optional) --prompt somealternatenametodisplay (or python39 -m venv env if you made a .bat file).
    3. type .\env\scripts\activate
    4. You should now have (env) or the alternate name at the beginning of your prompt
    5. type pip install windows-curses

    And everything should work now. Just remember to activate your environment whenever you want to use this.

    (To put a folder on the path) Let's make a new folder called myutils as an example at C:\myutils and put python39.bat in that folder.

    1. Right click My Computer
    2. Select properties
    3. On the right side under Related settings click on Advanced system settings.
    4. At the bottom of the Advanced tab, click on Environment Variables (You can also get to Environment Variables much faster by opening the start menu and starting to type environment, which should give you Edit the system environment variables).
    5. Under System variables, select Path, and then click Edit...
    6. Type C:\myutils, hit Enter, and press OK.

    Now, open a new terminal, and you'll be able to access any programs you put in that folder.

    In your path variable in Environment Variables, you can also change the default python interpreter. The default will be whichever one is at the top (which will probably be 3.9 now that you've just installed it).

    To change it back to 3.10, select C:\Program Files\Python310\Scripts\ and click Move Up until it's above the Python39 entries, then do the same with C:\Program Files\Python310\.