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.
Related
I am creating a .deb package that would run a shell script as preinst.
The shell script needs some input files, which would be available at where I have the .deb package, as below.
Package_located_directory $ >
mydebpackage.deb
inputfile1
inputfile2
I would just transfer all the files to the different machine at any location and install it with dpkg -i mydebpackage.deb
I tried using pwd in the preinst to get the current deb file located directory.
So, I can get the path of the inputfiles from the preinst script.
But if I run pwd from preinst , it is giving me / instead of the package located directory.
Also I tried passing pwd from the PIPE to achieve this, as below,
pwd | dpkg -i mydebpackage.deb
But I do not want to depend on the user input for the path.
Please guide me for getting the current deb package located directory path from inside of preinst script.
it's better to use postinst and modify the file on your system.
for example : Modify the file /etc/test/test.txt in postinst file
I was wondering if there is a way to set a default folder every time I open JupyterLab. Is there any command I can run through Anaconda PowerShell Prompt? Or a JSON property I can modify in settings tab? Thanks in advance!
If you want to open specific file in directory a, say a/notebook.ipynb but then navigate the file browser to directory b, relative to the root directory, you can use file-browser-path query in the navigation URL (documented here):
http(s)://<server:port>/<lab-location>/lab/tree/a/notebook.ipynb?file-browser-path=/b
You can use this method from command line thanks to LabApp.default_url traitlet:
jupyter-lab --LabApp.default_url='/lab/tree/a/notebook.ipynb?file-browser-path=/b'
You can skip the opening specific file part:
jupyter-lab --LabApp.default_url='/lab?file-browser-path=/b'
If you want to change the root directory, please see this answer which explains how to do so with ServerApp.root_dir traitlet (in older versions of Notebook<7.0 and JupyterLab<3.0 used to be named NotebookApp.notebook_dir). Again, you can use it from command line, and even specify an absolute path:
jupyter-lab --ServerApp.root_dir='/home/user/project/'
# or on Windows say:
# jupyter-lab --ServerApp.root_dir='C/users/user/project/'
You can combine the two approaches, e.g.:
jupyter-lab --ServerApp.root_dir='/home/user/project/' --LabApp.default_url='/lab?file-browser-path=/project_subdirectory'
If you want to persist the changes (for either default URL or root dir), see the previously linked answer which details how to persist configuration.
Follow the answer . Just edit the alias alias my_jupn='source /home/$USER/anaconda3/bin/activate && conda activate MyPy38 && jupyter-notebook --notebook-dir=/home/$USER/Documents/Jupyter_Notebook'
and for JupyterLab alias my_jupl='source /home/$USER/anaconda3/bin/activate && conda activate MyPy38 && jupyter-lab --notebook-dir=/home/$USER/Documents/Jupyter_Notebook'
N.B. Here MyPy38 is your active environment name. and if any error occurs then change $USER to your UserName. Lastly, /home/$USER/Documents/Jupyter_Notebook will be change according to your choice.
According to the jupyter.org:
I configured like this.
Terminal command active your envirnment by conda activate Your_env_name and then jupyter lab --generate-config. jupyter_lab_config.py should be created in dir /home/$USER/.jupyter directory.
Find
# c.LabApp.app_settings_dir = '' and uncomment.
Then give your directory like this.
c.LabApp.app_settings_dir = '/home/$USER/Documents/Jupyter_Notebook'
Similar for jupyter notebook. jupyter notebook --generate-config and then nu-comment and edit like c.NotebookApp.notebook_dir = '/home/UserName/Documents/Jupyter_Notebook'
**NB: /home/$USER/Documents/Jupyter_Notebook is my changed default dir. Change it according to your need. **
The command
jupyter notebook --generate-config
will create a config file.
The path to this file is displayed in your terminal or PowerShell.
Set the desired folder path as the string c.ServerApp.root_dir in this file and make sure you uncomment the line after you set the string.
Windows users will have to use double backslash in paths, e.g.:
c.ServerApp.root_dir = 'C:\\YOUR\\PATH'
I've followed the gsutil install guide following the Google Cloud instructions and I've updated GCloud components to the latest versions. I've just recently installed and configured GCloud to work with my credentials and project. First, I've used the following command to export a single collection I need from my Firestore :
gcloud firestore export gs://my-project-id.appspot.com --collection-ids=theCollectionINeed
Now I see this export is in my Firebase Console Storage section as a folder. Being the project Owner, I'd like to get this export into my local system. For that, I see I need to use gsutil to be able to copy it. Reading the instructions to download the object from your bucket, I've tried with the following command, but I got this error:
$ gsutil cp -r gs://m-project-id.appspot.com/2020-05-22T02:01:06_86154 .
Copying gs://lucky-level-dev-6ac34.appspot.com/2020-05-22T02:01:06_86154/2020-05-22T02:01:06_86154.overall_export_metadata...
OSError: The filename, directory name, or volume label syntax is incorrect.
I'm running this command using cmd in a Windows 10 environment.
I'd like to be able to download this folder from the cloud to my local drive.
Update
After being, I tried to change the bucket folder (object prefix) as suggested:
gsutil mv gs://my-project-id.appspot.com/2020-05-22T02:01:06_86154 gs://my-project-id.appspot.com/2020-06-23_someFolder
But trying again now throws me a new error:
gsutil cp -r gs://my-project-id.appspot.com/2020-05-22_someFolder .
Copying gs://my-project-id.appspot.com/2020-05-22_someFolder/2020-05-22T02:01:06_86154.overall_export_metadata...
OSError: Invalid argument.9.0 B]
Surely I need to change the name of the file too?
When doing the cp -r gs:/bucket_name/folder . Gsutil will try to create a folder with "bucket_name" name in the current location, Windows doesn't allow the name of folders to have some special characters including the ':'
You can rename the bucket folder (object prefix) with the command #DazWilkin suggested gsutil mv gs://m-project-id.appspot.com/2020-05-22T02:01:06_86154 gs://m-project-id.appspot.com/new_folder_name and then try again with the new folder name.
Also check that all filenames inside the directory structure don't have the ':' character or any other special one.
(Posted solution from question author to place it in the answer section).
All I had to do was rename the inner file that also had colons in its name. Renaming it solved the problem!
In the case of a gcloud firestore export the issue can be avoided by specifying a directory:
# BAD this will auto generate a directory windows doesnt like
gcloud firestore export gs://my-bucket
# GOOD specify a directory
gcloud firestore export gs://my-bucket/firestore-backup
# copy as usual
gsutil -m cp -r "gs://my-bucket/firestore-backup" .
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.
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