Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with Python in STATA 17

    Hello Statalisters,

    I am currently trying to run a python code in STATA, however I have issues with the python setup.

    As instructed on the Stata Blog (https://blog.stata.com/2020/08/18/st...to-use-python/) I have have set the python_exec path (in my case "/opt/homebrew/anaconda3/envs/venv/bin/python" the virtual environment in which I have built the project) I also set the user path etc. However whenever I try to use anaconda to install packages, or even pip for that matter I get faced with an error stating that conda/pip cannot be found. In addition, when I try to activate python I get an error stating that stata failed to load the shared library ("... failed to load the shared library /opt/homebrew/anaconda3/envs/venv/lib/libpython3.7m.dylib. r(7100);" . I am not quite sure how to get around this, if there may be some manually set the library?

    I am able to install libraries using the version of python3 which stata finds when using the command "python search", however I am unable to install geopandas, as this specific library requires using anaconda to install, and is unfortunately the key to my code.

    Does anyone have any advice on how to resolve using anaconda within stata as a package manager?

    I would be extremely grateful for any advice!

    Thank you!

  • #2
    Maybe the folks from StataCorp will correct me, but I use Python all the time for my work, and my very general advice to you is DON'T use anaconda. Just get regular python and follow the instructions on the Stata blog, and be sure to set Python on your system pathway.

    My attempts at using anaconda were nightmarish- you're better off, in my opinion, skipping that and just getting Python without it. Geopandas is equally nightmarish.

    I will comment below my code to install it (from my do file) when I'm at my laptop


    Added: Okay I'm back. You don't want to know how much pain I went through to find this method myself, I swear it was the worst. Assuming you can now install stuff in Python, this is how I installed geopandas.
    Code:
    cls
    loc command wheel pipwin numpy pandas shapely gdal fiona pyproj six rtree geopandas
    
    loc n: word count `command'
    
    disp `n'
    
    foreach x of loc command {
        
    !    py -p -m pip uninstall `x' -y
    }
    
    !    py -m pip install wheel
    !    py -m pip install pipwin
    cls
    forv i = 3/`n' {
        
    loc a: word `i' of `command'
    !    py -m pipwin install `a'
    }
    Yes, the order of the macros matters for some reason. But now that I've got it. I use geopandas to do fun stuff like change coordinate projections and other things that only Python can do.
    Last edited by Jared Greathouse; 30 Mar 2022, 08:14.

    Comment


    • #3
      Hi Anne Denis,

      Are you running Stata from M1 Mac or Intel-based Mac? What Stata edition are you using?

      Also, can you type

      Code:
      $ file /opt/homebrew/anaconda3/envs/venv/lib/libpython3.7m.dylib
      in your terminal to check what architecture is it built for?

      Comment


      • #4
        Jared,

        Thank you so much for your answer, and thank you so much for all the effort to find the way to get Geopandas! I tried putting it into place manually but I am running into some issues, but I will play around with it some more. Again thank you so much for your help, I have been so frustrated with my attempts to get Anaconda to work on STATA, when it works perfectly every time outside of STATA!

        Zhao,

        When I type that into my terminal I get: " /opt/homebrew/anaconda3/envs/venv/lib/libpython3.7m.dylib: Mach-O 64-bit dynamically linked shared library x86_64 " . My Mac operates on the Apple M1 chip! Thank you!

        Comment

        Working...
        X