“COULD Beirut become the Silicon Valley of the Middle East?” So asked a Lebanese news website in 2015. With an educated population, relatively liberal culture and large banking system, Beirut, the capital of Lebanon, seemed well-placed to become a hub for internet startups in the region. But there was at least one glaring problem. “Let’s face it—the internet in Lebanon [is] abysmally bad!” wrote Tony Fadell, the Lebanese-American co-creator of the iPod, in November. Due to government mismanagement, the country has some of the slowest download speeds in the world.

Across the Middle East in recent years, young men and women have created new products, started new companies and inspired hopeful talk of replicating the startup scenes in America and Europe. These entrepreneurs are a potential boon to the region’s economies, which suffer from slow growth and high unemployment, especially among the young. A pity, then, that so many obstacles stand in their way—and that so many are put there by governments. No place in the Arab world comes close to Silicon Valley in terms of dynamism. But, slowly, progress is being made, say entrepreneurs.

To understand what startups in the region are up against, consider that most of them will fail. That is true throughout the world, but in a country like Egypt, with no bankruptcy law, failure can mean a prison term if debts are not paid on time. Closing a company can take five to ten years and reams of paperwork. Those that stay in business must navigate outdated legal and regulatory systems that make it difficult to do things that are routine for startups elsewhere, such as paying employees with stock options. This is on top of the challenges that affect all Egyptian firms, such as rising prices and predatory officials.

Elsewhere the story is much the same. In countries such as Jordan and Lebanon, which claim to be startup-friendly, it is actually quite difficult to start up (see chart). Across the region, labour laws tend to make it hard to hire and fire workers, especially foreigners, even though schools fail to equip many locals with desirable skills, such as coding. Tax authorities are often confounded by startups, says Con O’Donnell, who started Sarmady, an Egyptian online-media company, which he sold to Vodafone in 2008. “They don’t understand the Amazon model,” says Mr O’Donnell, referring to the e-commerce giant, which lost money but grew quickly during its first two decades.

Amazon is thought to be in talks to buy Souq, a large online retailer based in the United Arab Emirates (UAE). Founded in 2005, Souq is often touted as a success story by investors in the region. But Souq apart, high barriers to trade have prevented e-commerce more generally from taking off. Getting goods through customs can be a bureaucratic nightmare, made worse by high tariffs, varying regulations and fluctuating currencies. “People talk about the region as if it is 200m people, but try to ship to these people,” says Louis Lebbos, the founder of AstroLabs, a hub for tech startups in Dubai. Several well-funded ventures have tried—and failed. Souq, which anyway ships mostly to the six countries in the Gulf Co-operation Council, a customs union, is the rare exception. E-commerce is one of several industries in which startups could do much more to fill market needs. Others include financial technology, as most Arabs do not have bank accounts or credit cards; and health care, with rates of obesity and other diseases rising across the region. But firms in these industries often have to seek approval from slow-moving government agencies. This can add years to a business plan. “In more developed systems, startups are more willing to jump ahead of regulation and the regulation catches up,” says Mr Lebbos. “But here the axe falls on those who jump ahead.” For decades, the region’s socialist-minded governments showed little interest in encouraging private enterprise. Many leaders are wary of empowering young people, who may also seek more political freedom. But as the region’s economies struggle, there is pressure on governments to improve their handling of startups—and to keep up with each other. In November, when Mr Fadell tweeted about Lebanon’s slow internet, Saad Hariri, the prime minister, quickly responded: “I am listening Tony, it’s on top of our future government agenda.” In Egypt the cabinet has just approved the country’s first bankruptcy law, one of several economic reforms aimed at encouraging investment. Several governments have also injected money into the system and guaranteed some of the risk involved in backing startups. Most notably, Lebanon launched a $400m package four years ago to encourage lending from banks. Such outlays, paired with the relatively small number of worthy startups in the region, have led to fears of a bubble. But more recent investments have been smaller and more organic. Last year, for example, Morocco received some $50m from the World Bank to create two new venture-capital funds, part of a plan to cultivate its growing startup scene, while international investors poured $275m into Souq and $350m into Careem, a ride-hailing app based in the UAE.

In most countries there are now clusters of startups, brought together by co-working spaces like Astrolabs in Dubai or Cogite in Tunisia, which have connections to accelerators, incubators and investors. Collaboration is common. Last month the Greek Campus, a hub for startups in downtown Cairo, hosted the Rise-Up summit, one of the largest gatherings of entrepreneurs in the region. Many young geeks aim to do good as well as make money. Abdelhameed Sharara, who started the event in 2013, says he was motivated by the failures of the Arab spring. “I felt there was another way to make it happen.” Many in attendance share his sense of purpose. “We are figuring out how to feed people better, how to empower women, how to educate children,” says Waleed Abd El Rahman, the founder of Mumm, a home-cooking delivery service in Cairo.

Unfortunately, the difficulty of doing business in the region, and the repressive nature of most governments, have caused many of the brightest minds to move abroad. But these challenges also force those who remain to think creatively about how to work around the system. And this makes for better companies, say many entrepreneurs. “If you can succeed in a country like Egypt, everywhere else is easy,” says Mr Sharara.