Raspberry Pi change path variable in profile not working - path

I would like to make my python script available to wherever I am. my python script is in /usr/share/pyshared/compteur so I have added the command to my .profile file export PATH=$PATH:/usr/share/pyshared/compteur
I rebooted my raspberry but if I try python compteur.py, it says it doesn't find the file.
How can I make this work?
ls -l folder gives
-rwxr--r-- 1 pi users 1273 Nov 30 15:26 camera.py
-rwxr--r-- 1 pi users 842 Nov 30 15:26 upload.py
head gives
head /usr/share/pyshared/compteur/camera.py
#!/usr/bin/env python
# Camera version 0.1
import RPi.GPIO as GPIO
from subprocess import call
import time
import ConfigParser
def main():

You can solve the problem by adding the command to your .bashrc (or .zshrc) file.
source $HOME/.profile
And restart your terminal. And all path setting in ~/.profile can work normally.

Related

Cannot find files that should be inside my running docker container

I'm doing some work with the reverse engineering tool angr, and I'm trying to run it in a container.
My current directory looks likes this:
ask#Garsy:~/Notes/ethHack/wetransfer-85179d/Export$ ls
angry.py impossible_password_location.csv report.md
impossible_password.bin impossible_password_strings.txt test.txt
I then run a specific angr image like so:
ask#Garsy:~/Notes/ethHack/wetransfer-85179d/Export$ sudo docker run -it --rm -v $pwd:/local angr/angr
Where I believe that using $pwd:/local should give me acces to the before shown files inside the container (following [this][1] guide [5:40]).
I run the container, and try to write some python:
(angr) angr#38b067fffc2d:~$ ipython3
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import angr
In [2]: angr.Project("/impossible_password.bin")
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-2-3f794a899665> in <module>
----> 1 angr.Project("/impossible_password.bin")
~/angr-dev/angr/angr/project.py in __init__(self, thing, default_analysis_mode, ignore_functions, use_sim_procedures, exclude_sim_procedures_func, exclude_sim_procedures_list, arch, simos, engine, load_options, translation_cache, support_selfmodifying_code, store_function, load_function, analyses_preset, concrete_target, **kwargs)
124 self.loader = cle.Loader(thing, **load_options)
125 elif not isinstance(thing, str) or not os.path.exists(thing) or not os.path.isfile(thing):
--> 126 raise Exception("Not a valid binary file: %s" % repr(thing))
127 else:
128 # use angr's loader, provided by cle
Exception: Not a valid binary file: '/impossible_password.bin'
where it can't find the file. Same goes for local/impossible_password.bin". How do I get the files of my current direcotry to be available when I spin up the container?
[1]: https://www.youtube.com/watch?v=9dQFM5O4KFk

uwsgi upgrade to python3.7 to fix ImportError: No module named 'encodings'

Honestly, I have no idea what I am doing, so be gentle with me. I am trying to use uwsgi to run my django application on a aws ubuntu instance. I have a virtual environment with python3.7 running, but when I try to run uwsgi. I get this in the logs:
*** Starting uWSGI 2.0.14 (64bit) on [Sun Jan 5 14:51:32 2020] ***
compiled with version: 5.4.0 20160609 on 20 October 2016 05:56:34
os: Linux-4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018
nodename: ip-172-31-41-139
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /home/ubuntu/web/graff
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3804
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /home/ubuntu/web/graffuwsgi.sock fd 3
Python version: 3.5.2 (default, Oct 8 2019, 13:06:37) [GCC 5.4.0 20160609]
Set PythonHome to /home/ubuntu/.virtualenvs/graff
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Here is my uwsgi.conf
# file: /etc/init/graffuwsgi.conf
description "uWSGI server for graff"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/local/bin/uwsgi --home /home/ubuntu/web/graff/ --socket /home/ubuntu/web/graffuwsgi.sock --chmod-socket=666 --module=graff.wsgi --pythonpath /home/ubuntu/web -H /home/ubuntu/.virtualenvs/graff --logto /home/ubuntu/web/logs/graffuwsgi.log --chdir=/home/ubuntu/web/graff --chmod-socket=666
It seems like python3.5 just doesn't work anymore. I feel like I've had to replace python3.5 with 3.7 in several places lately to fix various bugs, and I have it in my head that if I can get uwsgi to run python3.7 instead of 3.5 then that will solve this error too. Anyway, any help is much appreciated.
Looks like your uwsgi is compiled with different python version, make sure you compile with python 3.5
PYTHON=python3.5 uwsgi --build-plugin "/usr/src/uwsgi/plugins/python python35"
mv python35_plugin.so /usr/lib/uwsgi/plugins/python35_plugin.so
chmod 644 /usr/lib/uwsgi/plugins/python35_plugin.so
you can follow this guide:
https://www.paulox.net/2017/04/04/how-to-use-uwsgi-with-python3-6-in-ubuntu/
The source of error is PythonHome (pyhome, venv, home) setting.
See at the official Python docs on Environment variables
Is your path /home/ubuntu/.virtualenvs/graff suited for Python requirements?
In short:
Use pythonpath (pp) and let the system to find modules.
You can set several repeated options in your uwsgi config to custom modules search, eg:
pythonpath = /opt/web2py/
pythonpath = /opt/anaconda/lib/python3.9/site-packages/
So, I had the same error. And it was fixed by editing uwsgi vassal config.
I thing the core of problem that virtual envs are created with symlinks or have some inner relative paths, so an isolated process inside uwsgi could not find modules.

Running Lua script on OpenWRT directly (without running lua first)

On OpenWRT, I have a Lua script on_new_device.lua that runs fine if I execute lua on_new_device.lua; however, I'd like to run it simply by executing ./on_new_device.lua.
Executing ./on_new_device.lua returns this error...
root#router:~# ./on_new_device.lua
-ash: ./on_new_device.lua: not found
The file has execute permissions...
root#router:~# ls -la ./on_new_device.lua
-rwxrwxrwx 1 root root 1094 Jun 18 11:06 ./on_new_device.lua
The file starts with #!/usr/bin/lua...
root#router:~# head -1 ./on_new_device.lua
#!/usr/bin/lua
How can I execute this file directly?
Can you wrap it in a script?
Copy this into a test.ash file:
#!/bin/ash
/usr/bin/lua /[path]/on_new_device.lua
Then chmod 755 on test.ash, and then you can run:
./test.ash
Bah, the problem was that the lua script was created on a Windows machine and had \r\n line endings. Saving the file with \n line endings solved the issue.

Cannot execute gradle from the command line even though it's on my path

I have the following in ./bash_profile
export SRCROOT=/users/benjamin.beasley/work/svn/ccdev
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk_dev/Contents/Home
export PATH=$PATH$:~/tools/tools-versions/gradle-2.2.1/bin
export PATH=$PATH$:~/tools/activator
In ~/tools/tools-versions/gradle-1.12/bin, I do
drwxr-xr-x# 4 xxx.xxx WORKDAYINTERNAL\Domain Users 136 Nov 12 11:47 .
drwxr-xr-x# 13 xxx.xxx WORKDAYINTERNAL\Domain Users 442 Apr 29 2014 ..
-rwxr-xr-x# 1 xxx.xxx WORKDAYINTERNAL\Domain Users 5071 Apr 29 2014 gradle
-rwxr-xr-x# 1 xxx.xxx WORKDAYINTERNAL\Domain Users 2395 Apr 29 2014 gradle.bat
echo $PATH$:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin$:/Users/xxx.xxx/tools/tools-versions/gradle-2.2.1/bin$:/Users/xxx.xxx/tools/activator90566
so I get the gradle executable which is executable. I can execute it from this directory. But if I start a new shell, and type "gradle" it says command not found. But I "echo $PATH$" and I see that the full canonical path to the ~/tools/tools-versions/gradle-2.2.1/bin folder is there.
However I can execute activator which is an executable in the ~/tools/activator directory. I have no clue why bash knows about activator and not gradle.
In summary:
gradle is executable by this user
gradle can be run from the command line.
gradle is in the $PATH$ environment variable
other programs such as activator, which are also in $Path$ are executable anywhere in terminal regardless of directory which is what I want to be true of gradle.
Unix environment variables are $PATH not $PATH$ (they aren't like Windows env vars).
This is causing your problem.
This path is busted: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin$:/Users/xxx.xxx/tools/tools-versions/gradle-2.2.1/bin$:/Users/xxx.xxx/tools/activator90566
Notice the 90566 at the end? That's from $$ having been expanded to the current process id when you set the variable.
None of these are paths that actually exist or work:
/opt/X11/bin$
/Users/xxx.xxx/tools/tools-versions/gradle-2.2.1/bin$
/Users/xxx.xxx/tools/activator90566

Erlang causes page faults

When I run the script described here with my user, everything is well:
lorenzo#enzo:~/erlang/pei$ time erl -noshell -smp enabled -S 4 -s fib4 main 10000000
real 0m54.952s
user 1m16.090s
sys 0m0.070s
When I run it as root, it crashed:
lorenzo#enzo:~/erlang/pei$ sudo time erl -noshell -smp enabled -S 4 -s fib4 main 10000000
[sudo] password for lorenzo:
74.68user 0.04system 0:53.56elapsed 139%CPU (0avgtext+0avgdata 66064maxresident)k
0inputs+0outputs (0major+8306minor)pagefaults 0swaps
The error is reproduceable.
My questions are:
Can someone try to explain me what is happending there?
Is it a problem with the erlang runtime or with my OS?
Can someone reproduce this error?
I am running erlang 5.7.4 on ubuntu natty with kernel
Linux enzo 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
on a Phenom X4.
Why do you think it crashed? time just shows more info when running as root. Page fault is not an error but just the way virtual memory works.
The difference between the two runs is that in the first run, you're running the shell builtin time, but in the second run, you're running whatever sudo finds in the path, which is /usr/bin/time. These two tools have different output formats.
$ type time
time is a shell keyword
$ time echo
real 0m0.000s
user 0m0.000s
sys 0m0.000s
$ type /usr/bin/time
/usr/bin/time is /usr/bin/time
$ /usr/bin/time echo
0.01user 0.00system 0:00.00elapsed 1000%CPU (0avgtext+0avgdata 2784maxresident)k
0inputs+0outputs (0major+217minor)pagefaults 0swaps

Resources