Poetry config - command: poetry not found, but path added to bashrc and shrc files. export path command caused directory error running script - python-poetry

I am a new linux/python user trying to get poetry set up. Basically I can make the poetry command work by using the export path statement, but that only causes a directory issue when executing script. Ive downloaded poetry using the command:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
I know that it's installed because if I try and run that again, it says it already downloaded. I run into the error:
command: poetry not found
I used
nano ./bashrc
nano ./shrc
in terminal and I've edited both of those with
export PATH="$HOME/.poetry/bin:$PATH"
then, I'm following instructions to run a set of scripts under directory "thermalproc" that I've been given, and the path is ~/Desktop/VideoProcessing/thermalproc-20220625/thermalproc . I'm to use the command
poetry run thermalproc
the only thing that I have done to make the command work is to use that export line directly in the terminal, and that does allow the command to work, but if i run just the command as so:
joshua#Andrea-G750JZA:~$ poetry run thermalproc
it returns
RuntimeError
Poetry could not find a pyproject.toml file in /home/joshua or its parents
at .poetry/lib/poetry/_vendor/py3.8/poetry/core/factory.py:369 in locate
365│ if poetry_file.exists():
366│ return poetry_file
367│
368│ else:
→ 369│ raise RuntimeError(
370│ "Poetry could not find a pyproject.toml file in {} or its parents".format(
371│ cwd
372│ )
373│ )
and if I run in the directory of the script as I originally thought I should:
joshua#Andrea-G750JZA:~/Desktop/VideoProcessing/thermalproc-20220625/thermalproc$ poetry run thermalproc.
FileNotFoundError
[Errno 2] No such file or directory: b'/snap/bin/thermalproc.'
at /usr/lib/python3.8/os.py:601 in _execvpe
597│ path_list = map(fsencode, path_list)
598│ for dir in path_list:
599│ fullname = path.join(dir, file)
600│ try:
→ 601│ exec_func(fullname, *argrest)
602│ except (FileNotFoundError, NotADirectoryError) as e:
603│ last_exc = e
604│ except OSError as e:
605│ last_exc = e
Thanks for sticking it out this long, any advice would be greatly appreciated!

Related

Running a bash script gives various basic command not found error

I am new in bash scripting. I am trying to execute a bash script from my windows 11 system running in power shell terminal. I am in the same path where my bash file is present and I didnot add the folder path in env PATH.
The command I am using to execute the file -
bash test.sh
This is the error I am getting -
test.sh: line 1: FROM: command not found
test.sh: line 3: RUN: command not found
test.sh: line 6: RUN: command not found
test.sh: line 9: RUN: command not found
test.sh: line 12: ENV: command not found
Please suggest.
This is the bash script I am trying to execute -
FROM centos:centos7
# Get any CentOS updates then clear the Docker cache
RUN yum -y update && yum clean all
# Install MarkLogic dependencies
RUN yum -y install glibc.i686 gdb.x86_64 redhat-lsb.x86_64 && yum clean all
# Install the initscripts package so MarkLogic starts ok
RUN yum -y install initscripts && yum clean all
# Set the Path
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/MarkLogic/mlcmd/bin
# Copy the MarkLogic installer to a temp directory in the Docker image being built
#COPY MarkLogic-RHEL7-8.0-5.5.x86_64.rpm /tmp/MarkLogic.rpm
COPY MarkLogic-10.0-9.4.x86_64.rpm /tmp/MarkLogic.rpm
# Install MarkLogic then delete the .RPM file if the install succeeded
RUN yum -y install /tmp/MarkLogic.rpm && rm /tmp/MarkLogic.rpm
# Expose MarkLogic Server ports
# Also expose any ports your own MarkLogic App Servers use such as
# HTTP, REST and XDBC App Servers for your applications
EXPOSE 7997 7998 7999 8000 8001 8002
# Start MarkLogic from init.d script.
# Define default command (which avoids immediate shutdown)
CMD /etc/init.d/MarkLogic start && tail -f /dev/null
As said by #Inian, the file is a Dockerfile but not a shell script.
You would run:
docker build .
to build a docker image from the Dockerfile.

`command not found` when using Bash Script to Install & Run a Software

I am trying to create a Bash script that downloads a .sh file, runs it to install a program (Anaconda for Python), then run the command conda init to activate the default Anaconda environment base
However, running my bash script as shown
# !#/bin/bash
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
bash Anaconda3-*-Linux-x86_64.sh -b
echo 'export PATH=~/anaconda3/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
conda init
conda env create -f environment.yml
gives the error
./foo.sh: line 6: conda: command not found
./foo.sh: line 7: conda: command not found
Why is conda not found when trying to use it from within the Bash script, but is found if I relogin to the terminal?
How can we fix the Bash script so that using conda works?

Docker entrypoint.sh not found

Following the instructions as outlined to deploy Duo CloudMapper to AWS environment and getting an error
Docker File
FROM python:3.7-slim as cloudmapper
LABEL maintainer="https://github.com/0xdabbad00/"
LABEL Project="https://github.com/duo-labs/cloudmapper"
WORKDIR /opt/cloudmapper
ENV AWS_DEFAULT_REGION=us-east-1
RUN apt-get update -y
RUN apt-get install -y build-essential autoconf automake libtool python3.7-dev python3-tk jq awscli
COPY cloudmapper/. /opt/cloudmapper
COPY entrypoint.sh /opt/cloudmapper/entrypoint.sh
# Remove the demo data
RUN rm -rf /opt/cloudmapper/account-data/demo
# Install the python libraries needed for CloudMapper
RUN cd /opt/cloudmapper && pip install -r requirements.txt
ENTRYPOINT /opt/cloudmapper/entrypoint.sh
Now building the docker image
C:\> docker build -t cloudmapper .
When I run the docker using the below command I get an error
C:/> docker run -t cloudmapper
Error
/bin/sh: 1: /opt/cloudmapper/entrypoint.sh: not found
Verified that the file exists in the appropriate location
Using Docker on Windows 10
Image in the dockerfile is python:3.7-slim
Assuming the images are removed and replaced with text and the question doesn't get closed.
bash can return "file not found" when
the entrypoint shell script is not marked executable for the current user
the hash bang in the entrypoint shell script points to a binary that does not exist
the shell script actually does not exist.
You can fix the first problem by ensuring you use the new --chmod flag to ensure the executable bit is set. Even if the user is root it is necessary that there is at least 1 executable bit set.
COPY --chmod=0755 *.sh /opt/cloudmapper/
ENTRYPOINT ["/opt/cloudmapper/entrypoint.sh"]
ps. This integrated COPY --chmod only works with buildkit enabled builds, so you might need to force buildkit, or split the chmod into a separate explicit RUN step.
The 2nd issue can be dealt with by ensuring the first line of entrypoint.sh uses sh rather than bash if you are using a lightweight base image like alpine:
#!/bin/sh
set -e
# etc
Also, if on Windows especially, ensure ALL files, especially the entrypoint .sh file, are set to utf-8 encoding with lf style line endings. As linux doesn't understand the cr, it will try to execute /bin/sh<cr> as the shell which clearly doesn't exist.
In terms of the file not existing, verify the entrypoint.sh is being copied into a location that is referenced by env.PATH, or that the entry point directive uses a fully qualified path.
--
edited to add cr-lf revelation.

Command not found with sudo, but works without sudo

I've installed a binary dep in my GOPATH at /home/me/go/bin to be used.
Running dep successfully executes the binary, however running sudo dep results in sudo: dep: command not found:
$ dep
Dep is a tool for managing dependencies for Go projects
Usage: "dep [command]"
...
Use "dep help [command]" for more information about a command.
$ sudo dep
sudo: dep: command not found
The paths are not the issue here:
$ echo $PATH
/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/home/me/.local/bin:/home/me/bin:/home/me/.local/bin:/home/me/bin:/home/me/go/bin:/home/me/.local/bin:/home/me/bin:/home/me/go/bin
$ sudo echo $PATH
/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/home/me/.local/bin:/home/me/bin:/home/me/.local/bin:/home/me/bin:/home/me/go/bin:/home/me/.local/bin:/home/me/bin:/home/me/go/bin
The paths are identical as me and as superuser both referencing the key directory /home/me/go/bin.
Why does running dep without sudo succeed but with sudo results in command not found?
By default, sudo does NOT pass the user's original PATH into the superuser process, and it gets some default PATH defined on the system. That's easy to see if you run "sudo env" to see the entire environment of the sudo'ed process:
$ sudo env | grep PATH
PATH=/sbin:/bin:/usr/sbin:/usr/bin
The command you tried, "sudo echo $PATH" doesn't check anything, because the shell first translates the $PATH to whatever value this variable has - and only then calls the command (sudo), so it just prints your outer environment's value :-)
To get your PATH to pass inside sudo, you can do something like this:
$ sudo PATH=$PATH sh -c env | grep PATH
PATH=/usr/share/Modules/bin:/usr/lib64/ccache:/home/nyh/gaps:/home/nyh/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/sbin:/sbin:/usr/games:/usr/local/android-sdk-linux/tools:/usr/local/android-sdk-linux/platform-tools:/home/nyh/google-cloud-sdk/bin
Basically the command I passed for sudo to run starts by setting PATH to $PATH (remember that $PATH is expanded by the outer shell, before sudo ever runs, so is the real path I want!) and running a shell (which will use this new PAT) to "env". As you can see, env did get the right path. You can replace "env" by whatever program you wanted to run.

How to run a programme inside a virtual environment from a script

I have set up the google assistant sdk on my Raspberry Pi as shown here: https://developers.google.com/assistant/sdk/prototype/getting-started-pi-python/run-sample
Now in order to re-run the assistant I have worked out the two commands are
$ source env/bin/activate
and
(env) $ google-assistant-demo
however I want to automate this process into a script that I can call from rc.local (followed by an &) in order to make the assistant boot from start up.
However if I run a simple script
#!/bin/bash
source env/bin/activate
google-assistant-demo
the assistant does not run inside the environment
my environment path is /home/pi/env/bin/activate
How can I have it so the script starts the environment and then runs the assistant inside the virtual environment?
EDIT: In the end I went with the following method:
using this as a base :
https://youtu.be/ohUszBxuQA4?t=774 – thanks to Eric Parisot
You will need to download the src file he uses and extract its contents into /home/pi/src/
However with a few changes.
I did not run gassist.sh as sudo, as it gave me the following error:
OpenAlsaHandle PcmOpen: No such file or directory
[7689:7702:ERROR:audio_input_processor.cc(756)] Input error
ON_MUTED_CHANGED:
{‘is_muted’: False}
ON_START_FINISHED
ON_ASSISTANT_ERROR:
{‘is_fatal’: True}
[7689:7704:ERROR:audio_input_processor.cc(756)] Input error
ON_ASSISTANT_ERROR:
{‘is_fatal’: True}
Fix: DO NOT run as sudo
If gassist.sh gives an error about RPi.GPIO you need to do https://youtu.be/ohUszBxuQA4?t=580:
$ cd /home/pi/env/bin
$ source activate
(env) $ pip install RPi.GPIO
(env) $ deactivate
And then I did sudo nano /etc/profile
and the appended this to the end:
#Harvs was here on 24/06/17
if pidof -x "gassist.sh" >/dev/null; then
echo ""
echo "/etc/profile says:"
echo "An instance of Google Assistant is already running, will not start again"
echo ""
else
echo "Starting Google Assistant..."
echo "If you are seeing this, perhaps you have SSH within seconds of reboot"
/home/pi/src/gassist.sh &
fi
And now it works perfectly, and inside the virtual enviroment :)
found solution here :https://raspberrypi.stackexchange.com/a/45089
Create a startup shell script in your root directory (I named mine "launch"), make it executable too :
sudo nano launch.sh
I wrote it that way :
#!/bin/bash
source /home/pi/env/bin/activate
/home/pi/env/bin/google-assistant-demo
Save the file
Edit the LXDE-pi autostart file
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
Add this to the bottom of that file
./launch.sh
reboot
Scripts run from rc.local execute in the root directory (or possibly in the home directory of the root user, depending on the distro, I think?)
The easy fix is to code the full path to the environment.
#!/bin/bash
source /home/pi/env/bin/activate
google-assistant-demo
# or maybe /home/pi/google-assistant-demo
There is no need to explicitly background anything in rc.local
In the end I went with the following method:
using this as a base : https://youtu.be/ohUszBxuQA4?t=774 – thanks to Eric Parisot
However with a few changes.
You will need to download the src file he uses and extract its contents into /home/pi/src/
I did not run gassist.sh as sudo, as it gave me the following error:
OpenAlsaHandle PcmOpen: No such file or directory
[7689:7702:ERROR:audio_input_processor.cc(756)] Input error
ON_MUTED_CHANGED:
{‘is_muted’: False}
ON_START_FINISHED
ON_ASSISTANT_ERROR:
{‘is_fatal’: True}
[7689:7704:ERROR:audio_input_processor.cc(756)] Input error
ON_ASSISTANT_ERROR:
{‘is_fatal’: True}
Fix: DO NOT run as sudo
If gassist.sh gives an error about RPi.GPIO you need to do https://youtu.be/ohUszBxuQA4?t=580:
$ cd /home/pi/env/bin
$ source activate
(env) $ pip install RPi.GPIO
(env) $ deactivate
And then I did sudo nano /etc/profile and the appended this to the end:
#Harvs was here on 24/06/17
if pidof -x "gassist.sh" >/dev/null; then
echo ""
echo "/etc/profile says:"
echo "An instance of Google Assistant is already running, will not start again"
echo ""
else
echo "Starting Google Assistant..."
echo "If you are seeing this, perhaps you have SSH within seconds of reboot"
/home/pi/src/gassist.sh &
fi
And now it works perfectly, and inside the virtual enviroment, and in boot to CLI mode! :)

Resources