WSL Variable
- WSLでディレクトリで別Windowで起動する方法
# export PATH=$PATH:"/mnt/c/Users/ユーザー名/AppData/Local/Programs/Microsoft VS Code/bin"
export PATH=$PATH:"/mnt/c/Program Files/Microsoft VS Code/bin"
Ubuntu Condition
Git Variable
- Githubで事前に新規repoを作成後、新規ユーザーがGitにpushする場合:
- error内容$ git push origin main error: src refspec main does not match any error: failed to push some refs to 'https://github.com/XXXX/XXXX.git'
- 対処
- 原因は、プッシュしたいリモートリポジトリのブランチ名と、プッシュしようとしているローカルのブランチ名が異っていることです。git init git add . git commit -m "1st" git config --global user.email "you@example.com" git config --global user.name "Your Name" git config --global user.email "shiny@mydomain.com" git config --global user.name "Shiny" git commit -m "1st" ブランチ確認 git branch * master git branch -m master main git branch -M main git remote add origin https://github.com/xxx/xxx.git git push -u origin main Username for 'https://github.com': xxx Password for 'https://xxx@github.com': ※Passwordは、事前に取得しているGihubのTOKENを貼り付けます。これでOK!
- GitのUbuntuへ導入
- UbnuntuにSSHが既にインストールされているか確認します。 SSH-Client,Serverともにインストールされている。
/#SSHの確認
$ dpkg -l | grep ssh
ii  libssh-4:amd64                       0.9.3-2ubuntu2.2                      amd64        tiny C SSH library (OpenSSL flavor)
ii  openssh-client                       1:8.2p1-4ubuntu0.3                    amd64        secure shell (SSH) client, for secure access to remote machines
ii  openssh-server                       1:8.2p1-4ubuntu0.3                    amd64        secure shell (SSH) server, for secure access from remote machines
ii  openssh-sftp-server                  1:8.2p1-4ubuntu0.3                    amd64        secure shell (SSH) sftp server module, for SFTP access from remote machines
ii  ssh-import-id                        5.10-0ubuntu1                         all          securely retrieve an SSH public key and install it locally
- 最初から入っていると思うが,確認はターミナルで、以下のようにバージョン出てくれば大丈夫、、
/# gitのバージョン管理
$ git --version
git version 2.33.1
- 入っていない場合はインストールします。
$ sudo apt install git
- GitHubへの登録
- GitHubサイト
- アカウントの作成
- GitHubのウェブページからアカウントを作る
 (ユーザー名:TechRZN、パスワード:xxxxxxxx、メール:tech@raizin.net) 
- WSL-ubuntuとSSHによるgitの連携設定
WSLとGitHubサイトの両方で設定します。 4-1.WSL上でSSHの公開鍵の生成
- .sshフォルダーを作って、中に移動して鍵をつくる
- IT:tech@raizi.net PW:adminDE_s0
  /# 秘密鍵と公開鍵の生成
  matsu@hpPC:~$ mkdir .ssh
  matsu@hpPC:~$ cd .ssh
 $ ssh-keygen -t ed25519 -C "tech@raizi.net"
  Generating public/private ed25519 key pair.
  Enter file in which to save the key (/home/matsu/.ssh/id_ed25519): TechRZN
  Enter passphrase (empty for no passphrase): adminDE_s0
  Enter same passphrase again: adminDE_s0
  Your identification has been saved in TechRZN
  Your public key has been saved in TechRZN.pub
  The key fingerprint is:
  SHA256:cYVWSjEwdVkEdfWnY1KJgHDdDKKmN1Xcz2/5lfBNuV8 tech@raizi.net
  The key's randomart image is:
  +--[ED25519 256]--+
  |      ..=*OO=*+ +|
  |       o.==*=. o.|
  |      o o.o .oo +|
  |     o . o   oooo|
  |    . o S   . *o=|
  |     . .     o *E|
  |               .=|
  |                o|
  |                 |
  +
-[SHA256]
–+
4-2. SSH秘密鍵をssh-agentに追加します。
別の名前でキーを作成した場合、または別の名前の既存のキーを追加する場合は、コマンドのid_ed25519を秘密キーファイルの名前に置き換えてください。
~~~bash
  $ ssh-add ~/.ssh/id_ed25519 ←TechRZN 置き換える
  Enter passphrase for /home/matsu/.ssh/TechRZN: //adminDE_s0
  Identity added: /home/matsu/.ssh/TechRZN (tech@raizi.net)
4-3. GitHubのアカウントにSSHキーを追加します。
- SSH公開鍵(TechRZN.pub)をクリップボードにコピーします。
  $ cat TechRZN.pub
  ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGmRI9AbSL7H6jRINzqGB9rFXQUENt+PMl/idf1m7ZGz tech@raizi.net
4-4. GitとSSH 接続のテスト
/#接続テスト
$ ssh -T git@github.com 
The authenticity of host 'github.com (52.192.72.89)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.192.72.89' (RSA) to the list of known hosts.
Hi TechRZN! You've successfully authenticated, but GitHub does not provide shell access.
- 結果のメッセージにユーザー名が含まれていることを確認してください。 - 「Hi TechRZN!」なのでユーザー名は「TechRZN」とわかります。
 
- Configファイルの作成 - /# ($pwd)matsu@hpPC:~/.ssh $ touch config Host github HostName github.com User git IdentityFile ~/.ssh/TechRZN
- 再度の接続確認 - /# ($pwd)matsu@hpPC:~/.ssh $ ssh -T git@github.com Warning: Permanently added the RSA host key for IP address '13.114.40.48' to the list of known hosts. Hi TechRZN! You've successfully authenticated, but GitHub does not provide shell access.- 上記「GitHubとやりとりする」でssh接続について設定するのは面倒で
 - ~/.gitconfig [url "github:"] InsteadOf = https://github.com/ InsteadOf = git@github.com:- を追記してあげれば解決でした。 
 ところで、pushInsteadOfを使うとpushだけに適用出来るようです。
Python Variable
- 仮想環境作成
- ※Ubuntu22.04では、「sudo apt-get update」⇒「sudo apt update」を使います。 
- Dockerでは、Dbianなので「apt-get update」を使います。 - sudo update-alternatives --config python3 Selection Path Priority Status =========================================================== Selection Path Priority Status =========================================================== 0 /usr/bin/python3.10 130 auto mode 1 /opt/Python-3.9.0/python 3 manual mode 2 /usr/bin/python3.10 130 manual mode * 3 /usr/bin/python3.11 100 manual mode 4 /usr/bin/python3.8 110 manual mode
- Ubuntuなどで、デフォルトのPythonとは違うPythonをインストールし、update-alternatives でデフォルトを変更した場合、apt updateを実行すると、標題のようなModuleNotFoundError: No module named ‘apt_pkg’が表示されてうまくいかないことがあります。 
- 対処 - sudo vi /usr/lib/python3/dist-packages/CommandNotFound/db/creator.py sudo vi /usr/lib/cnf-update-db
- 1行目の「/usr/bin/python3」を「/usr/bin/python3.11」に書き換えて保存する。 
- 仮想環境の作成
- Pythonをアップグレードしたらvenvが作成できなくなった場合の対処
(pipなしでvenv環境を作成)python3 -m venv --without-pip <プロジェクト名>
- 以下ようにするcd /matching/ python3 -m venv --without-pip ./env (directoris) . ├── .dockerignore ├── Dockerfile ├── db.sqlite3 ├── env ├── home ├── manage.py ├── matching ├── requirements ├── requirements.txt └── search (acrivate:アクティブ化) source env/bin/activate
- (注意)バージョン管理(gitなど)を使用している場合は、プロジェクトのディレクトリになります。 その中のディレクトリは、バージョン管理から除外する必要があります。