Skip to content

Java issues #339

@jousheinfo

Description

@jousheinfo

Hello, Im trying to run a code using neqsim for plotting phase envelope of a CO2 mixture, but I keep getting the following error:

AttributeError: Java package 'neqsim' is not valid

I have in Environment Variables:

C:\Users\xxx\AppData\Local\Programs\Eclipse Adoptium\jdk-25.0.1.8-hotspot\bin

I have installed Eclipse Temurin as suggested in the description, and I have also installed jpype by using conda install -c conda-forge jpype1. I have also given the paths in the code as shown below, but I keep getting the same error: AttributeError: Java package 'neqsim' is not valid

Please help, I dont know what else to do.

import os
import jpype
import matplotlib.pyplot as plt

-----------------------------

1) JVM path (from JPype)

-----------------------------

jvm_path = jpype.getDefaultJVMPath()
print("Using JVM:", jvm_path)

-----------------------------

2) NeqSim JAR paths (from your dir output)

-----------------------------

jar_java11 = r"C:\Users\xxx\anaconda3\Lib\site-packages\neqsim\lib\java11\neqsim-3.1.3.jar"
jar_java8 = r"C:\Users\xxx\anaconda3\Lib\site-packages\neqsim\lib\java8\neqsim-3.1.3-Java8.jar"

Join them into a single classpath string

classpath = os.pathsep.join([jar_java11, jar_java8])
print("Using classpath:", classpath)

-----------------------------

3) Start JVM with NeqSim jars

-----------------------------

if not jpype.isJVMStarted():
jpype.startJVM(
jvm_path,
"-ea",
f"-Djava.class.path={classpath}",
convertStrings=False,
)
print("JVM started with NeqSim jars")

-----------------------------

4) Now import NeqSim thermo tools

(do NOT import neqsim before startJVM)

-----------------------------

from neqsim.thermo.thermoTools import *

-----------------------------

5) Build CO2–N2 mixture and plot PT envelope

-----------------------------

gas = fluid("srk") # SRK EOS
gas.addComponent("CO2", 0.7) # 70% CO2
gas.addComponent("nitrogen", 0.3) # 30% N2
gas.setMixingRule(2) # classic mixing rule

plt.figure(figsize=(8, 6))
phaseenvelope(gas, True) # True => P–T envelope plot

plt.title("P–T phase envelope – CO$_2$/N$_2$ (0.7 / 0.3)")
plt.xlabel("Temperature [K]")
plt.ylabel("Pressure [bar]")
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions