That said, violence spiked significantly after the Mexican government decided to use the army to combat the drug cartels (10 or so years ago). So maybe if drugs were legal within Mexico and we completely refused to have any part on policing their traffic across the border, we might have a more peaceful situation, albeit still one in which organized crime has a huge influence in politics in most or all of the country's territory. Then again, at this point the cat might be out of the bag regarding the violence... a lot of it involves cartels fighting each other for control of different regions or routes at this point.
What does it take for the Mexican government to prohibit the oil export? It does seem that Mexico is some sort of energy/resource-extraction site for the US and for that drug cartels are looked upon as collateral damage. Can it learn from Brazil which doesn't export oil as much? Or is it the case of pseudo democratic government held hostage by a handful of multinational corporations?
That said, a lot of the revenue for the federal government comes from oil exports. This further means that very little of PEMEX revenue gets re-invested into PEMEX, since it mostly goes to pay for what would otherwise be a huge federal deficit every year. It is also widely believed that there are strong political pressures from the U.S. not to reduce oil exports. So, in general, it's not easy for Mexico to prohibit oil exports without creating a huge crisis and/or majorly affecting trade relations.
The above becomes even more complicated when you add things like corruption, shared/disputed territorial water reserves (the Gulf of Mexico has large areas which fall under the territorial waters of the U.S., Mexico and Cuba, but access to oil deposits in those areas is not necessarily equal...) or contraband of "stolen" oil by drug cartels. But at a large scale, the main issue is: the federal government depends on oil exports and trade with the U.S. which might be partially conditioned on oil exports.
(Disclaimer: I am going to add to my posts that all this comes from the perspective of someone who was born and lived most of his life in Mexico and follows what I believe to be reasonable news sources. I am not a subject expert on: organized crime, Mexican law, Mexican trade relations, etc... you get the idea.)
Though if the activities themselves were legal, then a cartel that did not itself engage in violence would have recourse to the state, which is probably also cheaper for the cartel than engaging in violence themselves.