python global module installation when using remote SSH extension - python

I use remote-SSH to connect the server(ubuntu 20.04) and I find that if I click the button to install the module of python, it is only installed for one user.
For example:
xxx is not installed, install?
Then I find that the command in the terminal is :
pip install -U module_name --user
So I try to add the configuration in settings.json and install again.
"python.globalModuleInstallation": true
The terminal has no response, however. Is this a bug?
Though I can type the install command in terminal by myself, I still want to know if vscode can install the module globally by itself.
Thanks.

To install it on the global level (for all users) you need to install it as the root user or as an administrator.
In short you must give the admin privileges.
Use sudo for linux or run you VS code as admin.
Running the VScode as admin solved my issue. Give it a try.

Related

"Defaulting to user installation because normal site-packages is not writeable" python message

Whenever I try to install a new python package I get this message first :
Defaulting to user installation because normal site-packages is not writeable
even though I have administrator rights and I am running my py scripts and installation commands on my computer.
Any ideas why I keep getting this message before every and each pip installation?
Thanks in advance
While this most likely is to be avoided, the only option I found to work is to use the --ignore-installed switch such as:
pip install -U --ignore-installed python-openstackclient
as root which allowed python to overwrite all old distro files with the correct new versions.
This is an old question, but it mirrored my problem well. After running python3 -m virtualenv myproject, it created myproject/local/bin/activate instead of myproject/bin/activate, and after sourcing this file, pip3 install some_package would report Defaulting to user installation because normal site-packages is not writeable and proceed to install packages as the user rather than the virtual environment.
The fix for both issues was:
sudo pip3 uninstall virtualenv
sudo apt install -y python3-virtualenv
This second command will be different for non-Debian distributions.
I had this problem. you can copy packages file to AppData>Roaming>Python>Python3.(X)>script directory
work for me!
first I need to ask when you open cmd, is python added to path? when you type 'python' in cmd does something happen? If not, try to add python to path, otherwise if that doesn't work, try re-installing python. Also which version of python do you have? Does this happen with every package you try to install? Finally if nothing works, try to change the download location of python, and run cmd as admin/without admin, try both.
For anyone who does not wanna reinstall python, if u get the defaulter message, then all you have to do is go to AppData>Roaming>Python>Python3.(X)>site-packages. Cut the folders that are related to the package(U can identify by seeing the date modified), and paste the folders in originally installed python.exe destination then>Lib>site-packages. Hopefully when you restart the code editor modules will work. I did this and it worked.

Install Anaconda and access python for all users

I am trying to install anaconda for all the users on ubuntu 18.04. I installed anaconda at /root/anaconda3.
After that i edited the path in in /etc/environment to include the anaconda path.
When i login as a user i can see the path as
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/anaconda3/bin:/snap/bin: No such file or directory
I dont know why the No such file or directory is showing up.
when i try to run python it does not detect python.
Command 'python' not found, but can be installed with:
apt install python3
apt install python
apt install python-minimal
Ask your administrator to install one of them.
You also have python3 installed, you can run 'python3' instead.
I want to use anconda's python. I am able to use anaconda python as root user but not as other users. how do i make it work for all users?
Typically, /root is the root user's home directory and is accessible to root user only. One way to overcome the issue is to change the permissions of this root directory.
sudo chmod -R 777 /root
Be warned though that doing this not advised since changing files that are critical to system may cause it to become unstable.
Other way is to install anaconda in a different directory and assigning permissions to the install directory. The instructions to do that can be found on this link.
Hope this helps.

pip doesn't work even after add to environmental variable windows

I installed pip with get-pip.py, and it seemed that it was done successfully, and I added environmental variables. However, pip doesn't work (not recognized as internal or external command).
It doesn't work even if I write on the command line:
"C:\Users...\python-3.7.1-embed-amd64\Scripts\pip.exe" install numpy
I use windows 10, python 3.7, and i don't have admin rights. I edited user variables, also i asked admin to edit system environmental variables, but it didn't helped.
In case write path to pip.exe manually in the command line, it doesn't work as well.
(Pip and other expected files present in the Script folder!)
env path
pip install
To install packages, you need admin rights.
Start "cmd" as administrator.
Write your command
If you get error like:
Not recognized as internal or external command
if you get this error when you write "help" or other system commands, try start cmd using another way.
else, write not:
pip install package
but:
py -m pip install package
if you need python shell:
py

Installing pyobjc on a Mac

I am facing problems installing pyobjc on my mac.
Basically I have to install pyobjc on a new Mac System in the system default python. I have so far tried easy_install, pip and downloading the pkg file and installing. All give me a error in different ways. Some give me a error saying certain safari files are missing other cant due to some permission being denied even though I am running them through sudo su.
I then found a fix.
pip install pyobjc --user
This worked and I could access all the modules I required, but then if I try running python through sudo, I cant access those modules.
Can anyone suggest a fix for this.
NOTE: I don't mind a different method to install also. Also I have not tried brew due to some previous difficulties with it.
NOTE 2: I need to be able to access those modules using all users on the computer, the root user and me(the non-root user)
i had to (temporarily) move (using sudo) /Library/Python/2.7/site-packages/Extras.pth to another name before I could install the current pyobjc.
This is what works for me:
sudo mv /Library/Python/2.7/site-packages/Extras.pth /Library/Python/2.7/site-packages/Extras.pth_orig
pip install --upgrade pyobjc
sudo mv /Library/Python/2.7/site-packages/Extras.pth_orig /Library/Python/2.7/site-packages/Extras.pth
It appears that something in the .pth file interferes with the install, but does not impede running pyobjc.
but then if I try running python through sudo, I cant access those
modules.
Because sudo python basically means run python as some other user (root by default). That user may have a different set of environment variables, including $PATH.
Some of linux distributions use older Python version for root user,like centos.If the Python verison you're running with sudo isn't correct,you can't access those modules installed by pip.
So in my opinion,if you didn't get permission issues,you don't need to use sudo ,using sudo might bring unexpected mistakes(most environment variables issues),maybe chown or chmod can fix those issues.
So here are my plans:
Plan A: The best way is to try to use virtualenv.
Plan B: Install modules without sudo command,if got permission errors(not very common),try --user .
Install to the Python user install directory for your platform.
Typically ~/.local/, or %APPDATA%Python on Windows.
In most cases,you should modify your PYTHONPATH.See details from How do I access packages installed by pip --user.
Plan C: All related commands are executed with sudo.sudo pip install (all modules) and sudo python script.py.Not a good idea.

pip install access denied on Windows

I am trying to run pip install mitmproxy on Windows, but I keep getting access denied, even with cmd and PowerShell using the Run as Administrator option.
WindowsError: [Error 5] Access is denied: 'c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u\\cryptography-0.9.1\\.eggs\\cffi-1.1.2-py2.7-win-amd64.egg\\_cffi_backend.pyd'
How can I make this work?
For Windows, in Command Prompt (Admin) try to run pip install using the Python executable:
python -m pip install mitmproxy
This should work, at least it worked for me for other package installation.
Change your Python installation folder's security permissions by:
Open a Python shell
Go to task manager
Find the python process
Right-click and open location
The folder will open in explorer, go up a directory
Right-click the folder and select properties
Click the security tab and hit 'edit'
Add everyone and give them permission to Read and Write.
Save your changes
If you open cmd as admin; then you can do the following:
If Python is set in your PATH, then:
python -m pip install mitmproxy
Personally, I found that by opening cmd as admin then run
python -m pip install mitproxy
seems to fix my problem.
Note:- I installed python through chocolatey
One additional thing that has not been covered in previous answers and that often cause issues on Windows and stopped me from installing some package despite running as admin is that you get the same permission denied error if there is another program that use some of the files you (or pip install) try to access. This is a really stupid "feature" of Windows that pops up many times, e.g. when trying to move some files.
In addition I have no clue how to figure out which program locks a particular file, so the easiest ting to do is to reboot and do the installation before starting anything, in particular before running e.g. Spyder or any other Python-based software. You can also try to close all programs, but it can be tricky to know which one actually holds a file. For a directory for example, it is enough that you have an Explorer window open at that directory.
As, i am installing through anaconda Prompt .In my case, it didn't even work with python -m pip install Then, i add this
python -m pip install <package_name> --user
It works for me.
Like: python -m pip install mitmproxy --user
Another you should try that run the Command Prompt as Run as Administrator and then try pip install. It should work either.
Open cmd with "Run as administrator" and execute the command pip install mitmproxy. It will install it.
Try to give permission to full control the python folder.
Find the python root directory-->right button click-->properties-->security-->edit-->give users Full Control-->yes and wait the process finished.
It works for me.
The cause in my case was having a jupyter notebook open, which was importing the relevant library; the root cause seems to be windows error due to the file being open / in use (see also #Robert's answer, and the recommendation to reboot).
So another thing to verify is that no other python processes are running.
For me, shutting down the notebook server solved the issue.
Try to delete the folder c:\\users\\bruno\\appdata\\local\\temp\\easy_install-0fme6u manually and then retry the pip command.
When all else fails, try quitting your IDE. I had many cases in which PyCharm was causing this. As soon as I quit PyCharm, I was able to finally install my packages from the command line. Alternatively, you can also install through PyCharm itself in Settings -> Project: xxx -> Project Interpreter -> +.
Opening command prompt As Administrator just worked for me without using Python executable.
Right click on command prompt shortcut and choose "Run as Administrator".
Then run the following command.
pip install Django
In my case,
Windows Defender is blocking the process and every time I run a pip command it will show pop up of security threat.
What I do is exclude the python folder.
Below are the steps:
Click the Windows icon, search "Windows Security" app, and open it
Choose Virus & threat protection on the left menu
Scroll down to Virus & threat protection settings
Click Manage settings
Scroll down to Exclusions
Click Add or remove exclusions
Click Add an exclusion, and choose Folder
Navigate to this path C:\Users{Your_User}\AppData\Local\Programs\Python
Select folder
Relaunch your Command prompt
Sometimes you just need to make sure you do not have any python environments running.
I met a similar problem.But the error report is about
[SSL: TLSV1_ALERT_ACCESS_DENIED] tlsv1 alert access denied (_ssl.c:777)
First I tried this https://python-forum.io/Thread-All-pip-install-attempts-are-met-with-SSL-error#pid_28035 ,but seems it couldn't solve my problems,and still repeat the same issue.
And Second if you are working on a business computer,generally it may exist a web content filter(but I can access https://pypi.python.org through browser directly).And solve this issue by adding a proxy server.
For windows,open the Internet properties through IE or Chrome or whatsoever ,then set valid proxy address and port,and this way solve my problems
Or just adding the option pip --proxy [proxy-address]:port install mitmproxy.But you always need to add this option while installing by pypi
The above two solution is alternative for you demand.
In my case, it didn't even work with python -m pip install
What I have done is, from a cmd as administrator:
PsExec.exe -i -s -d cmd.exe
In order to spawn a SYSTEM cmd, then pip install mitmproxy
;)
Open Command Prompt as Administrator.
To Install any Python Package use this command including --user.
pip install --ignore-installed --upgrade --user <packagename>
Had the same problem when installing pycaret.
I've solved in two different ways (that I'll list below).
Option 1
Upgraded pip with
python -m pip install --user --upgrade pip
Then
pip install --user pycaret[full]
Found a relevant discussion on the error here.
Option 2
Assuming one is using Anaconda, open Anaconda prompt, for the environment one is working with, as admin
And run
pip install --user pycaret[full]
or
pip install pycaret[full]
I also work in secure environment, Hence for install module I use this code:-
pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org
in last add your library name , such as :
pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org numpy
Run cmd.exe as an administrator then type:
python -m pip install
Running cmd as administrator solved for me. You can also try --user.
If you do not want to repeat the steps you need to give full access to anaconda folder.
Just close all the python files opened. And try to run as administrator. It will work.
e.g.
pip install mitmproxy

Categories