U.S. President Donald Trump said Monday he would meet Iran's president under the right circumstances to end a confrontation over a 2015 nuclear deal and that talks were underway to see how countries could open credit lines to keep Iran's economy afloat.

But Trump, speaking at a G7 summit in the French resort of Biarritz, ruled out lifting economic sanctions to compensate for losses suffered by Iran.

Trump told reporters it was realistic to envisage a meeting between him and President Hassan Rouhani in coming weeks, describing Iran as a country of "tremendous potential."

"I have a good feeling. I think he [Rouhani] is going to want to meet and get their situation straightened out. They are hurting badly," Trump said.

As he had in the first year of presidency in the face of North Korean missile tests, Trump alternated between being open to the possibility of talks at some future point and issuing threats.

"They can't do what they were saying they were going to do because if they do that, they will be met with really very violent force," said Trump, appearing to refer to Iran's recent combative rhetoric about its ability to attack U.S. interests.

"But they [Iran] have to stop terrorism," he added. "I think they are going to change, I really do."

French President Emmanuel Macron, host of the summit, told the same news conference that Rouhani had told him he would be open to meeting Trump. Macron said he hoped a summit between the two men could happen in coming weeks. Trump and Rouhani head to the United Nations General Assembly in September.

Rouhani is not Iran's top decision-maker. That role is held by the fiercely anti-American Supreme Leader Ayatollah Ali Khamenei, and anything agreed at a Trump-Rouhani encounter would be subject to Khamenei's approval.

European leaders have struggled to calm the deepening confrontation between Iran and the United States since Trump pulled Washington out of Tehran's 2015 nuclear deal with world powers and reimposed sanctions on the Iranian economy.

But Macron has spent the summer trying to create conditions for a pause to bring the two sides back to the negotiating table.

"What I hope is that in coming weeks, based on these talks, we can manage to see a summit between President Rouhani and President Trump," Macron said, adding that he believed if they met a deal could be struck.

Sanctions hurting Iran: Trump

Macron's efforts took a surprise turn on Sunday when Iranian Foreign Minister Mohammad Javad Zarif, who is under U.S. sanctions, flew to Biarritz, where he met with the French president as well as officials from Germany and England.

"I knew [Zarif] was coming in and I respected the fact that he was coming in. We're looking to make Iran rich again, let them be rich, let them do well, if they want," Trump said.

Trump said it was too early for him to meet Zarif.

Trump and French President Emmanuel Macron talk at the close of the summit. Within seconds of Macron talking about the need to maintain the goals of the 2015 nuclear deal with Iran, Trump again bashed the pact. (Francois Mori/The Associated Press)

The 2015 deal between Iran and six world powers, reached when Trump's predecessor Barack Obama was in office, aimed to curb Iran's disputed uranium enrichment program in exchange for the lifting of many international sanctions on Tehran.

Since ditching the deal, called the Joint Comprehensive Plan of Action, Trump has pursued a policy of "maximum pressure" to try to force Iran into broader talks to restrict its ballistic missile program and end its support for proxy forces around the Middle East.

Trump said he was not open to giving Iran compensation for sanctions on its economy. However, he said the idea under discussion would be for numerous countries to give Iran a credit line to keep it going.

"No we are not paying, we don't pay," Trump said.

"But they may need some money to get them over a very rough patch and if they do need money, and it would be secured by oil, which to me is great security, and they have a lot of oil… so we are really talking about a letter of credit. It would be from numerous countries, numerous countries."

While Trump's European allies also want fresh negotiations with Iran, they believe the nuclear deal must be upheld to help ward off the risk of wider war in the Middle East.

Iran should never be allowed to get a nuclear weapon, British Prime Minister Boris Johnson said.

"There is clearly an opportunity now for Iran to come back into compliance with the nuclear deal… and to resume dialogue, as well as to cease its disruptive behaviour in the region."

Macron and Prime Minister Justin Trudeau reiterated their support for containing Iran as prescribed in the 2015 agreement.