# Windows 10 version 2004 and up or 11 - release and development
A guide on how to set up a workspace and run ERPLibre on Windows 10 version 2004 and up or Windows 11. There are two methods of installation, one is automatic and the other manual.
**"WSL2 Ubuntu 22.04" will be referred as "WSL2"**
**"PyCharm Professional" will be referred as "PyCharm"**
## Install WSL2
Run Powershell with administrator rights and run the following command:
```bash
wsl --install -d Ubuntu-22.04
```
If you have trouble opening the Powershell with administrator rights, press `Windows + R`, enter the following line and press `OK`. You will be automatically prompted for administrator rights.
```bash
powershell.exe
```
### Troubleshooting - Optional
If you have issues enable virtualization options in BIOS is available (hyper-v, vt-x, etc). Search for `Turn Windows features on or off` in the Windows search bar and ensure that `Windows Subsystem for Linux` is turned on before restarting your machine.
Download and install the lastest Linux kernel update package from Microsoft with the following [link](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi):
Ensure all dependencies are installed correctly. Re-run the following command to fix any broken dependencies:
```bash
sudo apt-get install -f
```
### PostgreSQL Not Starting
Check the PostgreSQL service status with the following command:
```bash
sudo service postgresql status
```
If PostgreSQL is not running, try restarting it with:
```bash
sudo service postgresql restart
```
## Running ERPLibre
Everytime you restart your machine, the following command has to be executed to start the PostgreSQL service if it is not already running:
```bash
sudo service postgresql start
```
After that run this command in the root of the project:
```bash
./run.sh
```
## Verifying ERPLibre
While ERPLibre is running, make sure that you can connect to the following URL `http://localhost:8069` and have the ability to create, modify and remove databases.
## Set up Development Environment - PyCharm
### Install PyCharm
Install PyCharm from the following [link](https://www.jetbrains.com/pycharm/download/#section=windows):
Select `Connect to WSL` under `Remote Development`. After that select your Ubuntu instace ("Ubuntu-22.04"). Point `Project directory` to the root of the project. Once everything has been selected and filled out correctly, click on `Start IDE and Connect`.

Press `CTRL+ALT+S`, search for `interpreter` and inside the `Python Interpreter` page, click on `Add Interpreter` and select `Add Local Interpreter...`.
Make sure to select `Virtualenv Environment` on the left and the `Existing` radio button. Once theses are both selected properly, point your interpreter to the `../ERPLibre/.venv/bin/python` directory of the project and click on `OK`.

If these last steps to set up your development environment were unsuccessful, follow the next "Manual" steps to set up your environment.
## Manual Installation
### Install Python 3.10.14
You can delete the files that are left over in your home directory regarding the python installation when the steps have been completed succesfully.
Press `CTRL+ALT+S`, search for `interpreter` and inside the `Python Interpreter` page, click on `Add Interpreter` and select `On WSL...`.

Wait until PyCharm detects your WSL2 instance and press `NEXT`. Click on `System Interpreter` on the left, select the correct interpreter if it hasn't done so automatically and click `Create`.

Close the project's settings. Once PyCharm prompts you to import modules and allow it.
## Common problems with Windows Development
### Broken Terminal
Search for `terminal` in the settings, and under `Application Settings` in the `Shell path:` field enter the following line:
```bash
wsl.exe
```

### High Memory Usage warnings
If you experience high memory usage, click on `Help` in the toolbar and choose `Change Memory Settings` to increase the memory heap of the IDE.
### Missing or incorrect imported modules
PyCharm might not fully recognize some details from `requirements.txt` and `pyproject.toml` (e.g., specific module versions). If you encounter issues at runtime or while debugging, search for the correct version of the module and reinstall it using PyCharm's package manager.
### Can't run ERPLibre from PyCharm
If ERPLibre fails to run from PyCharm, execute the following command in the root directory of the project from the terminal in PyCharm or WSL2:
```bash
./script/ide/pycharm_configuration.py
```
### Can't restart ERPLibre
Run `htop` from the terminal in PyCharm or WSL2 and close the python processes related to ERPLibre to release the socket.