Installing package Golearn - linux

I'm try to install the package Golearn, following these instructions.
After running in the terminal
go get -t -u -v github.com/sjwhitworth/golearn
I tried to run (as required):
cd $GOPATH/src/github.com/sjwhitworth/golearn
However bash doesn't find this directory. What should I do?
(I'm using linux)

install the package Golearn
Example build, in /home/name/tmp/
git clone https://github.com/sjwhitworth/golearn.git
cd golearn/
## Completing the installation
## Run the following to complete installation
go get -t -u -v ./...
Using : Please (also) read the text file README.md .

I did the following and worked:
go get -t -u -v github.com/sjwhitworth/golearn
go: downloading github.com/sjwhitworth/golearn v0.0.0-20221228163002-74ae077eafb2
go: added github.com/sjwhitworth/golearn v0.0.0-20221228163002-74ae077eafb
go env GOPATH
/Users/<my_username>/go
cd /Users/<my_username>/go/pkg/mod/github.com/sjwhitworth/golearn#v0.0.0-20221228163002-74ae077eafb2
sudo go get -t -u -v ./...

The instruction of golearn maybe some outdated, you can follow my process:
cd into a empty folder, like /home/your/code/my_golearn, all commands below should be run at this floder
run go mod init my_golearn to init a go project, you will get a go.mod file
create a main.go file and fill it with code from https://github.com/sjwhitworth/golearn#getting-started
run go get github.com/sjwhitworth/golearn
run go mod download to get all dependencies
run go get github.com/sjwhitworth/golearn/knn, it's strange, but it doesn't work if this command miss, I think maybe the developer of golearn has some misuse of go mod
run wget https://raw.githubusercontent.com/sjwhitworth/golearn/master/examples/datasets/iris.csv -P datasets to get dataset you need
run go run ./main.go, you will get result same as https://github.com/sjwhitworth/golearn#getting-started
If you are not familiar with how to install dependency in a modern go project, it's better for you to go through https://go.dev/blog/using-go-modules

Related

Where does NPX store binaries after installation?

If I'm using npx to run a binary as a one-off, it'll output the following:
npx my-module
/// npx: installed 1 in 1.34s
/// Hello, from my module!
Where are these binaries stored by default? Does npx save the binaries after execution, a-la npm or does it just run them and then remove the files?
It's my understanding that npx will first look in the local node_modules/.bin diectory and then the /usr/local/bin directory, before it downloads the module. But I've checked both of those locations and don't see the new module...
npm version 7 will cache the packages in a _npx directory. It has a cache layout that apparently involves a hash. For example, for me npx shellcheck installs the executable in ~/.npm/_npx/cca5ebdff9ce100b/node_modules/.bin/shellcheck. (Note the cca5ebdff9ce100b.) However, I very much doubt that the algorithm can be relied upon to be consistent across versions of npx.
The whole point of npx is that you can run the packages without installing them somewhere permanent. So I wouldn't use that cache location for anything. I wouldn't be surprised if cache entries were cleared from time to time. I don't know what algorithm, if any, npx uses for time-based cache invalidation.
To get the location from which npx runs the package, you can use -p to tell it to install a package and then use which <executable> or command -v <executable> to get the path. So, for example, what I did above to get the location of the shellcheck executable was to run npx -p shellcheck which shellcheck or npx -p shellcheck command -v shellcheck. Those commands assume a Linux or other UNIX-like operating system. I'm not sure what the equivalent for Windows would be.
$ npx -p shellcheck command -v shellcheck
Need to install the following packages:
shellcheck
Ok to proceed? (y)
/Users/trott/.npm/_npx/cca5ebdff9ce100b/node_modules/.bin/shellcheck
$
In Windows, this would be:
C:\Users\{YourUserName}\AppData\Local\npm-cache\_npx\
or the bash shell equivalent of:
~/Local Settings/npm-cache/_npx/ etc.

No such file or directory error while running Docker image

I am learning Docker concept and trying to make a Docker image of my project. I have installed Docker Desktop for Windows and build the image successfully by using below command:
docker build -t ${IMAGE_NAME} .
But when I run following command docker run ${IMAGE_NAME}:${TAG} I am getting following file not found error:
D:\Projects\AI360\deep_auto_backbar_api>docker run dsbyprateekg:prateek_gupta
python3: can't open file '/Prepare_Dataset/server_engine/server.py': [Errno 2] No such file or directory
My project structure is looks like:
And my Dockerfile.txt has following instructions:
FROM python: 3.6-stretch
MAINTAINER PrateekG
# install build utilities
RUN apt-get update && \
apt-get install -y gcc make apt-transport-https ca-certificates build-essential
# check our python environment
RUN python3 version RUN pip3 --version
# Installing python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy all the files from the project's root to the working directory
COPY Prepare_Dataset/ .
# Running Python Application
CMD ["python3", "/Prepare_Dataset/server_engine/server.py"]
I suspect I am missing something related to file path. Please see my Dockerfile and my project structure and help me to find out what I am doing wrong here.
When you use COPY Prepare_Dataset/ . this will copy the content of the directory, not the directory itself so
CMD path become invalid /Prepare_Dataset/server_engine/server.py.
You need to use
COPY Prepare_Dataset/ ./Prepare_Dataset/
so when you copy you can verify
Step 5/7 : COPY Prepare_Dataset/ ./Prepare_Dataset/
---> Using cache
---> 2c5c15c23f65
Step 6/7 : RUN ls | grep "Prepare_Dataset"
---> Running in 54147bd4740c
Prepare_Dataset
Better to keep convention to avoid such error in future.
# SEt workdirectory
WORKDIR /app
# Now it will copy to /app/
COPY Prepare_Dataset/ ./Prepare_Dataset
CMD ["Prepare_Dataset/server_engine/server.py"]
You can verify you problem using below steps.
COPY Prepare_Dataset/ .
#You will see the content but not the directory
RUN ls /
You will not able to see the directory but you can grep the any file in it.
Step 5/7 : COPY Prepare_Dataset/ .
---> Using cache
---> e4eec046c860
Step 6/7 : RUN ls | grep "Prepare_Dataset"
---> Running in 23e4b2aab3d1
The command '/bin/sh -c ls | grep "Prepare_Dataset"' returned a non-zero code: 1
In my case I had to change the line separators from cr/lf (Windows) to lf (Unix/Linux/macOS). To do this in IntelliJ, you have to select your root folder in the Project window and the go to File -> File Properties -> Line Separators -> LF - Unix and macOS (\n)
Also see this answer
Make sure the value of TAG is proper. Check if container is getting launch or not using following command;
docker ps -a
Use an ENTRYPOINT instead of CMD and then you can use command line options in the docker run like in your example.
ENTRYPOINT ["python3", "Prepare_Dataset/server_engine/server.py"]
Reference: link
If others stumble across this, I hit the same error. But my issue was different:
# Error `No such file or directory`
ENTRYPOINT ["/bin/bash", "-c", "{$APP}"]
# Success
ENTRYPOINT ["/bin/bash", "-c", "$APP"]

Using SUDO with NVM?

How is it to execute something like sudo npm rebuild or sudo node if Node.js was installed by NVM ?
Each time I type sudo command, my console tries to execute npm or node program in /usr/bin/ or /usr/lib, neither of which do exist.
Try creating symlinks in /usr/bin or /usr/lib. Not a strong solution, but may be enough.
sudo ln -s /home/denny/.nvm/versions/node/v0.12.0/bin/npm /usr/bin/npm
sudo for writing in system location. Suggestions here may happen useful, especially rvmsudo or group access.
Other suggestion:
According to comment, you may try to create a bash script at /home/denny/npm.sh:
#!/bin/bash
PTH="/home/denny/.nvm/versions/node/$(node -v)/bin/npm"
$PTH
chmode it +x properly and create symlink with this:
sudo ln -s /home/denny/npm.sh /usr/bin/npm
Should always check for node -v and run npm from proper directory.
I needed to do this to run the Atom installation script, but I didn't want to permanently change my machine setup. So, I did:
sudo bash
and then I sourced the nvm.sh file in my user's home directory tree:
source /home/ada-lovelace/.nvm/nvm.sh
That let me run the necessary commands with root. Of course, this means the very next time I need to run node in a session with root I'll have to do these steps again, but I don't anticipate needing to do this in the near future.

How to create simple coffescript example without rails

I am new to coffeescript. I saw a coffeescript video in Rails casts.com. From that episode I understand how to convert the normal Js and Jquery to coffeescript code and the usage of coffeescript.
I am trying to create a coffeescript example without rails. I wetn through the coffeescript site. They first install Node.js. I tried to install node.js in windows and ubuntu, but I had failures. I followed the instruction as per this site:
http://howtonode.org/how-to-install-nodejs#ubuntu
For ubuntu I got "bash: ./configure?: No such file or directory" error when I execute the following command
./configure
Can anyone help me to create simple coffescript example without rails?
One more thing - In Mac "By the help of homebrew I can see the compiled js of coffescript code through compiled and Display Js window". Are there any options available in windows and ubuntu?
I would bet the easiest way to install Node.js on Ubuntu is through APT:
$ sudo apt-get install nodejs
It probably will get some outdated version but it can be enough for some tests.
If you prefer the latest version (which is a reasonable preference), I bet it would be easier to install Node.js from the dist package. Just copy and paste this on terminal:
wget http://nodejs.org/dist/node-v0.5.0.tar.gz && \
tar zvxf node-v0.5.0.tar.gz && \
cd node-v0.5.0 && \
./configure && \
make && \
sudo make install
This line will:
download the latest Node.js source code with wget http://nodejs.org/dist/node-v0.5.0.tar.gz
uncompress the downloaded source code with tar zvxf node-v0.5.0.tar.gz
enter into the source code with cd node-v0.5.0
set the build parameters with ./configure
effectively build the Node.js executable with make
install the built Node.js in your path with sudo make install
The && means "execute the next command if the previous command succeeds" (for example wget http://nodejs.org/dist/node-v0.5.0.tar.gz && tar zvxf node-v0.5.0.tar.gz means that we will download the package with wget and iff the download succeeds we will unpack the download file with tar. The backslashes (\) are here for allowing us to break all the series of commands in more than one line because, by default, we would have a big line:
wget http://nodejs.org/dist/node-v0.5.0.tar.gz && tar zvxf node-v0.5.0.tar.gz && cd node-v0.5.0 && ./configure && make && sudo make install
Then, you can install npm with this simple command, found in the own npm github page:
$ curl http://npmjs.org/install.sh | sudo sh
With npm, it will be too easy to install coffee, as you can see in the CoffeeScript page:
$ npm install coffee-script
Now, just run your tests:
$ coffee
coffee> a = key: 'value'
{ key: 'value' }
coffee> a.key
'value'
Does it look like to much work? You can try CoffeeScript in the language page. Just click in "Try CoffeeScript" and a console will appear to you.
For testing and demo purposes it may be sufficient to have your CoffeeScript compiled directly in browser. You can include the CoffeeScript compiler and your code in a tag.
This method is not efficient though so please use it for playing around.
Please see this section on how to set things up:
"text/coffeescript" Script Tags
Good luck!
Ubuntu 11.10 has an up-to-date package for CoffeeScript.
sudo apt-get install coffeescript

Where should I install node.js?

I'm wondering in which directory I should go to install node.js on a CentOS 5/cPanel server by executing the following commands mentioned in the Wiki:
git clone --depth 1 https://github.com/joyent/node.git
cd node
git checkout origin/v0.4 # optional. Note that master is unstable.
export JOBS=2 # optional, sets number of parallel commands.
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.profile
source ~/.profile
Please advise.
The more conventional locations for a multi-user system are:
/usr/bin/node
/usr/local/bin/node
But as #Raynos stated you can put it wherever you want to.
I like to install latest version of node.js using something called nvm.
Like Raynos said you are better of using node v0.4.8 instead of development branch to avoid broken packages.

Resources