Activating Venv in Bash without changing child directory - linux

Edit: Thanks to everyone commenting below. The purpose of this question was to figure out a way to execute the venv given that we are in a child directory and the venv folder is located in parent directory.
example: there are three folders inside parent directory:
/home/iamuser/ ls
.venv random_files pictures
Currently we are inside folder "random_files"(/home/iamuser/random_files) . We need to find out a way to start venv which is inside parent directory.
First way is to use cd .. to get to the parent directory**(/home/iamuser/)** , then type Source ./venv/bin/activate
Second way is to use the following command directly from "random_files" folder.
Source ../venv/bin/activate
This will start venv in "random_files" folder (child directory) without forcing us to change directories.
The issue is solved. I hope my answer helps someone.
*****************************OLD Thread *******************************
I have been trying how can I activate virtual environment without changing path.
While writing this question, I am at: /home/user
If I do cd .. I will go back one directory to the home, if I do cd .. again I will go back to the top of the tree.
At that place, I have my venv located.
To activate venv, I use cd.. twice to go to that position and then I type source venv/bin/activate. I am looking for a solution where I donot have to use cd.. twice
Can I get a script that could activate venv without forcing me to change directory.

You can use the absolute path
source /venv/bin/activate

Related

Run script relative to file location, not command line location in node

I'm not sure exactly what to call what I'm trying to do, but I have a node script that accesses a folder (./commands relative to the script file), but when I run the script from somewhere other than the folder, it is unable to find ./commands.
I.e. when I'm in the folder with the script in it, ./commands refers to \script-folder\commands, but when I'm on the desktop, the script looks in Desktop\commands and finds nothing.
Is there any way to tell the script to run relative to its own folder, or do I just have to hard-code the full location of the commands folder in the script?
./ means current working directory. you can check with pwd command.
You can use path.join(__dirname,yourpath);

Copying shell file to path

I'm new to WSL and Linux, but I'm trying to follow installation instructions for rhasspy (https://rhasspy.readthedocs.io/en/latest/installation/#windows-subsystem-for-linux-wsl). I have run the make install command successfully and the next step says I should copy rhasspy somewhere in my path but I can't quite figure out what copying to path means.
When installation is finished, copy rhasspy.sh somewhere in your PATH and rename it to rhasspy.
I added it to path but nothing changed so I was wondering if there is something I'm doing wrong. Right now when I run rhasspy on wsl it says rhasspy.sh: command not found. Any help would be really appreciated!
What it says is, put it in some place where the system will look for it when you type its name without full path in the shell.
There is an environment variable PATH that contains all those locations, separated by a :. (Check out echo $PATH.)
So, the author of these instructions leaves it up to you whether...
You want to copy the file to a location of your choice that is already in the PATH, such as /usr/local/bin or ~/bin.
Usually ~/bin is a good choice because it is per-user and doesn't pollute the system.
(Note that the directory ~/bin is added to the PATH by your .profile file only if it exists, so if you don't have this directory yet and create it now, you need to start a new login shell or run . ~/.profile1 before you can use it.)
- OR -
You want to create a new directory specifically for this application (say for example ~/opt/rhasspy) and append that directory to the PATH variable.
This can be done by adding the line export PATH=$PATH:~/opt/rhasspy to your ~/.profile file. Then, start a new login shell or reload the file using . ~/.profile1 for the changes to take effect.
If the directory in which this file is currently located is OK for you to keep permanently, then you can also just add that directory to the PATH instead of creating a new one.
Note: The PATH always contains directory paths in which the shell will look for executable files. It does not contain the actual file paths!
1: Yes, technically it is "cleaner" to log into a new shell or to run that one export statement manually instead of using . ~/.profile because the latter will apply things a second time that were already done before, so for example it can end up with the same directory in the PATH multiple times in the current session. In most cases that is fine though.
PATH is an environment variable. When you launch env, you see the list of known environment variables on your system.
In order to add something to your PATH variable, you need to take the variable, add the mentioned directory (preceeded by a semi-colon, most probably, as a separator) and store this again as the PATH variable. This can be done as follows (own example):
export PATH=$PATH:/home/this_user
the "PATH" it is referring to in linux is just inside the folder called /usr/bin. when you type a command into the terminal it looks for a program with that name inside the location. im not sure if this is the PATH you are looking for but hope it helps

Moving Git to another folder, but I've got a problem

My git was init in folder ~/ryan/pythonproject/ and then later on I started using PyCharm and it created a venv for the project after importing. So now I have:
~/ryan/pythonproject/venv/
The first directory has my original work on the project, and then it appears I have a duplicate of my work under the venv folder.
Whenever I commit/add/push it does the original folder as well as the venv folder.
What I would like to do is have Git stop monitoring the original folder and only have git under the venv folder only. What's the best way to do that?
If you want to stop monitoring a folder you can put it to the .gitignore file. So i.e. you have:
YourProject/venv/FolderA
YourProject/venv/FolderB
YourProject/FolderA
YourProject/FolderB
Then just add the lower two to the .gitignore .
But please think about it whether this is really what you want. Usually it is the other way around. Keep your files and ignore the build folder.

Adding a permanent value to $PATH on Raspbian

I am quite new to Linux so I'm sorry for my newbie question,
but for about and hour now I'm trying to add Node.js to $PATH with no luck :(
I've used the following line to add Node
PATH=$PATH:node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
it worked, but when I logged off the terminal and logged in again, the path disappeared.
Later I tried adding the same line to .profile , .logins.defs and .bashrc.
All didn't work so I removed the line.
Please help me with this!
P.S , when I added the line to .profile I was able to call Node, but when I changed my directory in order to navigate to a Node project directory, I received the following error:
-bash: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin/node: No such file or directory
You should add an absolute path, not a relative one. You added this to your path: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin. That's a relative path, not an absolute one (absolute paths start with a /). You can change your line to:
PATH=$PATH:DIR/node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
where DIR is the full path of the directory containing node-v0.10.24-linux-arm-armv6j-vfp-hard.
It's probably a good idea for you to read a bit on how this all works - it's not that complicated once you see it explained. See https://superuser.com/questions/238987/how-does-unix-search-for-executable-files for an example.
You have $HOME already set to your home directory.
So you can use this in your .profile:
PATH="$PATH:$HOME:$HOME/bin:$HOME/node-v0.10.24-linux-arm-ar‌​mv6j-vfp-hard/bin"
If you set it as an absolute path you will not be able to copy that .profile to another user who is set up similarly.
I see there is another question that deals with installing node.js on Debian - and must admit I am surprised it is installed per-user. So if you do the install for another login you might want to copy your .profile to the new login to solve this same issue. There would be no per-user editing required if you use the $HOME variable like this. Just a simple copy or cut and paste.
For reference, here is that other question/answer: install node.js on debian

Why can't I see paths that exist in OSX?

I am a windows developer switching over to OSX. I am very confused though. I am learning node.js and the documentation tells me to add a reference to nodemon at the path...
/usr/local/bin/nodemon
However when I am at the terminal and I type 'ls' I get the following output...
And that doesn't have a /usr/ folder ... And what is even more confusing is that if I do...
ls -a
Then I can see all my hidden folder with a folder in called .npm which seems to have all my modules. In windows this is easy it just installs all npm modules into %AppData%/npm or something but I just don't get it on OSX can somebody enlighten me please?
ls lists the directories and files in your current working directory.
You can find your current working directory with pwd (short for 'print working directory')
You can change your current working directory with the cd (change directory) command. In your case, you could run
cd /usr/local
ls
and it would show you the bin directory. Alternatively, you could directly run
ls /usr/local
As a special extra note, the Terminal Prompt itself actually displays the current working directory (by default). In your case, it shows ~, which is shorthand for the user profile directory, which the Terminal opens to automatically. It is generally /Users/<username>.

Resources