Code Monkey home page Code Monkey logo

Comments (3)

bnjmnp avatar bnjmnp commented on July 18, 2024

Hi, sorry I'm also no expert on Linux and don't know how to get around this. Maybe someone with enough knowledge reads this and can provide help.
When searching on the web about this you could look for questions like this: https://raspberrypi.stackexchange.com/questions/40105/access-gpio-pins-without-root-no-access-to-dev-mem-try-running-as-root in the past on Raspbian one needed root access to access GPIO's from within a Python script. Maybe the solutions of this can be transferred to your system.
I'd love to hear how you finally solved this.

from pysoem.

asmorgan24 avatar asmorgan24 commented on July 18, 2024

Just wanted to follow up on this. After digging into this for a couple of days, and working with some embedded engineers, here is a single (1) solution to this problem. There may be others, but this is the most streamlined. I will be spending time figuring out how to make this work best in a docker container, but for the time being you can use this method for both your home (base) python environment or virtual ones. It should also work with C++ and other languages as well, just with some modification of what your "executable" is. Assuming we are using python:

ll `which python`

You will get a response that looks something like this: lrwxrwxrwx 1 amorgan amorgan 9 Apr 26  2023 **/home/amorgan/miniconda3/envs/play_env/bin/python** -> **python3.8***

Now that you know you are using python 3.8 (or whatever one you are using), then run:

ll `which python3.8`

You will get a reply that looks like: rwxrwxr-x 2 amorgan amorgan 14718232 Nov 6 2019 **/home/amorgan/miniconda3/envs/play_env/bin/python3.8**

Now, you know that when you call python in command line, python3.8 (or whatever it is for your system) is what is being called to run the executable. Finally, you can open up permissions to your python executable by running:

sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' ~/miniconda3/envs/play_env/bin/python3.8

Where the final argument is the location of your python executable (as determined in step 2). Hopefully this helps out anyone trying to work with opening ports/adapters for ethernet/ethercat on linux/ubuntu systems.

from pysoem.

daironxuan avatar daironxuan commented on July 18, 2024
def request_root_permissions(m_path, m_pid):
    args = ["pkexec", "python3", m_path, str(m_pid)]
    process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    process.wait(60)
    if process.returncode == 1:
        return True
    else:
        return False
        
        
su_state = True
    if os.getuid() != 0:
        app_path = os.path.abspath(sys.argv[0])
        pid = os.getpid()
        su_state = request_root_permissions(app_path, pid)
        
        
        
# Do what you want.....

from pysoem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.