Can't import library in Python - python-3.6

Running python3 xx.py in my specific folder
shows Import Error
But, I go to my home directory ,and add the new files with same code
and then it can work well. Why?
I checked both sys.path in these two, the path is same

find pycache, init.py
ls -l
remove it
rm -rf "pycache" "init.py" it works!
Finally,it is solved

Related

Run jq command in git-bash

jq command not found after adding jq executable
installing jq on git bash
My usecase is more similar with above shared references. I tried to execute a hook that needs to parse a json file. When hook gets executed it throws bash: jq:command not found error. So. I downloaded jq-win64.exe file and copied it to /usr/bin in Git folder. Then from git-bash I run export PATH=$PATH:"/C/Program Files/Git/usr/bin/jq-win64.exe" command and there is no error but when I checked jq --version command it still shows bash: jq:command not found error
Am I missing something? I even tried in windows cmd but is of no use. Hope someone can help me.
Thanks in advance!!!
PATH contains directories. That means what you should do:
Rename jq-win64.exe to jq.exe or just jq. (e.g. cp ~/Downloads/jq-win64.exe /usr/bin/jq).
You don't have to export your path, /usr/bin is already part of it.
If you didn't rename the file to jq (or jq.exe), then you would have to run it as jq-win64 in your console.
You could also put the binary into ~/bin folder, which should be part of PATH too. If it isn't, you can add it. Then you don't need to mess with your global binaries folder.

ZSH Git prompt status stays always visible for a non-git directory

ZSH shell shows Git prompt status (master [?]) even if a directory isn't a git directory.
What could be the problem? Thanks in advance.
My .zshrc file:
export PATH=$HOME/bin:/usr/local/bin:$PATH
export ZSH=/Users/m3rkus/.oh-my-zsh
ZSH_THEME="spaceship"
plugins=(git)
source $ZSH/oh-my-zsh.sh
One of the higher level folder has probably a .git folder in it.
You can use #Adaephon suggested command to find where it is:
git rev-parse --show-toplevel

Google colab changing directory

I can't change my directory in Google colab. when I type cd it gives output like this '/content' I tried to change the directory using
import os
os.chdir("drive")
but it shows error No such file or directory: 'drive' . How to get rid of this?
If you want to change directory from google colab into google drive, connect to google drive first.
from google.colab import drive
drive.mount('/content/drive')
It will ask for authentication key that will be can be obtained
when signing in to your google drive
Change to the google drive directory.
%cd /content/drive/MyDrive/
For verifying:
!pwd
Your current directory is /content/drive/MyDrive/
Did you create a /drive directory? (By default, one does not exist. You'll need to mount your Drive using a recipe like this one.
Otherwise, create a directory first. For example,
!mkdir demo
%cd demo
!pwd
will show /content/demo.
First check for the current directory you are working in,
!pwd
Now, if you want to change the present working directory then,
import os
os.chdir('[path you want to move in]')
suppose path is
os.chdir('/content/drive/My Drive/Colab Notebooks/Data')
Now the directory 'data' is the current working directory.
You can check,
!pwd
/content/drive/My Drive/Colab Notebooks/Data
This indicates your directory has been changed successfully.
You can check the full example here.
https://colab.research.google.com/drive/1CSPBdmY0TxU038aKscL8YJ3ELgCiGGju#scrollTo=SWeWe_Bb8wO0
First, you have to install OCaml Fuse to use this feature on Google Colab, run the following command to install OCaml Fuse :
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
During the installation, (usually) Collab will ask you to insert code verification twice, just follow the link and accept the permission, then copy the code and paste to the form field that appear.
After the installation finish, run the below :
!mkdir drive
!google-drive-ocamlfuse drive
!ls -lla drive/"Colab Notebooks"
and see the output, and then you can refer to your file on your drive like these :
x = "drive/Colab Notebooks/blablablah/blah/file.p"
y = "drive/Colab Notebooks/blablablah/blah/file.p"
z = "drive/Colab Notebooks/blablablah/blah/file.p"
hope this can help you!
/content/ is the default directory in which all of your files and data are saved.
To change the directory you can do something like this:
Create a folder inside the /content/ which is recommended. Then run this:
import os
os.chdir('/content/folder_name')
If you run !pwd you could see the path changed to /content/folder_name
%cd /content/drive/MyDrive/folder/
!pwd
This will change your directory to the path you have set. You can check your changed dir by typing !pwd.

Why changing LD_LIBRARY_PATH has no effect in Ubuntu?

I was trying to deploy my application on Ubuntu 16.04. So i made a package with the following hierarchy -
Package
|
----bin
|
-----application
-----application.sh
-----Qt
|
-----necessary qt libraries
-----platforms
Here is the application.sh file -
#!/bin/sh
export LD_LIBRARY_PATH=`pwd`/Qt
./application
When i execute the application.sh file, it shows me that it cant find the libQt5MultimediaWidgets.so.5 file. But its in the Qt folder. Also when i print the ldd application from the application.sh file after exporting LD_LIBRARY_PATH it gives me following output -
Please check the marked parts. Can anyone please explain why the libraries from the Qt folder are not found even after exporting the LD_LIBARRY_PATH?
Edit:
So as suggested by #Zang, i have checked the debug log and here it is -
Please check the marked parts.
It seems like its actually trying the actual libQt5MultimediaWidgets.so and then report that its unable to find it. Can anyone please help me understand whats happening here?
Edit-2: As per suggestion from #Tarun, i have ran ls -al on my Qt folder. Here is the output -
All files in Your Qt directory are actually simlinks to non-existing files in the same directory, therefore they cannot be found.
If you look at the output of your ls -al
These are soft links that you have. Your softlink libQt5MultimediaWidgets.so.5 points to libQt5MultimediaWidgets.so.5.9.2 in the same directory and the file is not there at all. So you need to either set the correct softlink path or have the file in same directory
First
Could it be that the pwd is not where you assume it is?
You could try adding
# Figure out where the application.sh script is located
scriptpath="$( cd "$(dirname "$0")" ; pwd -P )"
# Make sure our pwd is that location
cd "$scriptpath"
in the top of your script (assumes bash shell, from here)
By doing this all relative paths to Qt folder will be valid.
Second
Maybe you should considder exporting your new LD_LIBRARY_PATH, like so (from here):
LD_LIBRARY_PATH=whatever
export LD_LIBRARY_PATH
Third
It may be useful to run ldconfig command for ld to update after changing the variable (from here):
sudo ldconfig
The file libQt5MultimediaWidgets.so is not present in /Desktop/package/bin/Qt according to the screenshots shown.

Implementing a selected unix path for a specific application (e.g. pytest)

I have two versions of pytest installed, one locally in a directory in my home directory, and one that is installed in /usr/local/bin.
The version of pytest installed in the /usr/local/bin is 2.2.4 and I don't have sudo rights to upgrade it to the newer version, 2.3.4, but need some tests to run with 2.3.4.
Is there a way to redirect the path so that it always uses the pytest in my home directory over the pytest in the /usr/local/bin directory when I invoke pytest?
Because there is a need to run many tests, it would be more convenient to have a shortcut!
You should add a directory to your $PATH that contains the copy of pytest you would like to use. For example, place pytest in ~/bin and add ~/bin (or $HOME/bin) to your path:
PATH="$HOME/bin:$PATH"
export PATH
As indicated, place the new directory at the front of the path so that your copy of pytest (and whatever else you put in ~/bin) will be found first.
Even better, put those two lines into ~/.profile so that your $PATH will be updated every time you log in.

Resources