从用户本地目录运行 python 包

从用户本地目录运行 python 包

我正在共享主机,有限SSH使用权。

没有须藤特权。

并且某些文件夹有一些限制,如下所示:

这是终端的输出ls -al

drwx--x--x  17  myusername  myusername  4096    May 23 03:02    .
drwxr-xr-x  3   root        root        4096    Mar 27 11:02    ..
lrwxrwxrwx  1   myusername  myusername  34      Mar 27 01:31    access-logs -> /usr/local/apache/domlogs/myusername
-rw-------  1   myusername  myusername  640     Mar 29 23:56    .bash_history
-rw-r--r--  1   myusername  myusername  18      Oct 14  2014    .bash_logout
-rw-r--r--  1   myusername  myusername  176     Oct 14  2014    .bash_profile
-rw-r--r--  1   myusername  myusername  124     Oct 14  2014    .bashrc
drwxrwx--x  4   myusername  myusername  4096    Mar 27 11:02    .cagefs
drwxr-xr-x  2   myusername  myusername  4096    Mar 27 01:21    .cl.selector
-rw-------  1   myusername  myusername  21      Mar 27 01:21    .contactemail
drwx------  5   myusername  myusername  4096    Mar 31 18:49    .cpanel
-rw-r-----  1   myusername  myusername  1       Mar 31 18:14    cpbackup-exclude.conf
drwxr-x---  2   myusername  mail        4096    Mar 31 20:25    etc
-rw-------  1   myusername  myusername  16      Apr 29 02:50    .ftpquota
-rw-r--r--  1   myusername  myusername  140     Mar 27 01:21    .gemrc
drwxr-x---  2   myusername  nobody      4096    Mar 27 01:21    .htpasswds
-rw-------  1   myusername  myusername  13      Mar 31 18:46    .lastlogin
drwx------  2   myusername  myusername  4096    May 17 02:05    logs
drwxr-x---  8   myusername  myusername  4096    Mar 27 01:21    mail
-rw-------  1   myusername  myusername  44      Mar 27 16:26    .my.cnf
drwxrwxr-x  2   myusername  myusername  4096    Mar 29 11:33    perl5
drwxr-x---  3   myusername  myusername  4096    Mar 27 01:21    public_ftp
drwxr-xr-x  6   myusername  nobody      4096    May 25 20:23    public_html
drwx--x--x  4   myusername  myusername  4096    Mar 27 01:54    .softaculous
drwx------  2   myusername  myusername  4096    Mar 29 11:30    .ssh
drwxr-xr-x  5   myusername  myusername  4096    Mar 31 18:14    ssl
drwxr-xr-x  8   myusername  myusername  4096    Mar 29 20:24    tmp
drwx------  2   myusername  myusername  4096    Mar 27 16:22    .trash
lrwxrwxrwx  1   myusername  myusername  11      Mar 27 01:21    www -> public_html

我的目标是安装Python使用包画中画&虚拟环境

由于限制,我尝试使用无 sudo 方法来安装画中画虚拟环境进入用户本地, 下列的本教程

=============

这些步骤一切顺利:

$wget https://bootstrap.pypa.io/ez_setup.py -O - | python - --user

服务器的响应是:

...........
...........    
Processing setuptools-16.0-py2.6.egg
Copying setuptools-16.0-py2.6.egg to /home/myusername/.local/lib/python2.6/site-packages
Adding setuptools 16.0 to easy-install.pth file
Installing easy_install script to /home/myusername/.local/bin
Installing easy_install-2.6 script to /home/myusername/.local/bin

Installed /home/myusername/.local/lib/python2.6/site-packages/setuptools-16.0-py2.6.egg
Processing dependencies for setuptools==16.0
Finished processing dependencies for setuptools==16.0

这一步还有:

$wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py -O - | python - --user


............
............
Installing collected packages: pip, argparse, wheel
Successfully installed argparse-1.3.0 pip-7.0.1 wheel-0.24.0

现在,我的问题是:

我怎样才能运行这些包?:D

正如您所见,我无法访问文件夹~/.local/,它没有出现在ls -al您上面所看到的内容中!

pip在 SSH 终端中写入以下内容:

$ pip
-bash: pip: command not found

$ python pip
python: can't open file 'pip': [Errno 2] No such file or directory

$ cd /.local/
-bash: cd: /.local/: No such file or directory

$ /.local/bin/pip
-bash: /.local/bin/pip: No such file or directory

$ python /.local/bin/pip
python: can't open file '/.local/bin/pip': [Errno 2] No such file or directory

抱歉,如果我的问题令人困惑或者不够清楚!

答案1

使用 pip 安装

$ mkdir my_project_folder
$ cd my_project_folder
$ curl -L -o virtualenv.py https://raw.github.com/pypa/virtualenv/master/virtualenv.py
$ python virtualenv.py venv
$ source venv/bin/activate

至此,您已经准备好虚拟环境,如果您想安装更多软件包,可以这样做:

$ pip install YOUR_PACKAGE --user

因此,你可以安装软件包而无需触及系统 Python 目录(通常在 ~/.local/ 中)

相关内容