pythonpathsciposerrorpyscipopt

OSerror in using psycipopt in python


I wanted to use pyscipopt and I keep getting this error: OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\Program Files\SCIPOptSuite 8.0.3;D:\softwares\scip-8.0.3\bin'

`

 import pyscipopt
 

 model = pyscipopt.Model()

 # Set the solver parameters (optional)
 model.setParam('presolving/maxrounds', 0)  # Disable presolving 
 to solve the model as-is

 # Define the variables
 n = 3  # Number of rows
 m = 4  # Number of columns
 x = [[model.addVar(vtype='B', name=f'x_{i}_{j}') for j in 
 range(m)] for i in range(n)]


 z3 = 0
  for i in range(n):
     for j in range(m):
         f_i = ...  # Define your objective coefficient f_i for 
   variable x_i_j

    z3 += f_i * x[i][j]
   model.setObjective(z3, sense='minimize')

   model.optimize()


  if model.getStatus() == 'optimal':
  # Get the optimal solution
solution = [[model.getVal(x[i][j]) for j in range(m)] for i in 
  range(n)]
    print('Optimal solution:')
      for i in range(n):
          for j in range(m):
            print(f'x_{i}_{j} = {solution[i][j]}')
  else:
       print('No feasible solution found.')

   model.freeProb()
   `           

Solution

  • You need to create a new Conda environment. Open a terminal (on Windows you can use cmd (Command Prompt) or PowerShell) or Anaconda Prompt. To create an environment type in terminal:

    conda create --name myenv
    

    Name myenv is the name of your environment, you can put whatever you want, usually it is something like your project name. (You can also specify which Python version you want to use, for example conda create --name myenv python=3.11.) Then you need to activate the environment you just created so we can use it to run your program:

    conda activate myenv
    

    Before running the program we need to install package PySCIPOpt, we will use the command recommended in PySCIPOpt's README:

    conda install --channel conda-forge pyscipopt
    

    To run your program, you need to navigate to the folder (Windows logo, Ubuntu logo) where your program is located and then run your program with the command:

    python programName.py
    

    Filename programName.py is the name of your program.

    This is a simple way to run your program from the terminal, if you are using an IDE then you can set up Anaconda with your IDE.