How to fix “IOError: [Errno 2] No such file or directory” when making Virtual Environments

倾然丶 夕夏残阳落幕 提交于 2021-01-29 15:21:59

问题


Whenever I try to use the 'virtualenv VirtualEnvironmentName' command or the 'virtualenv -p python3.8 VirtualEnvironmentName' command it says "IOError: [Errno 2] No such file or directory." I just want to make Virtual Environments, but I always get that error saying "No such file or directory." Thanks in advance.


回答1:


To create a virtual environment, you must specify a path.

Then you can activate the python environment by running the following command:

your_working_directory\\Scripts\\activate

Most likely, the problem is that you're using a relative path for the directory.

Let me clarify how Python finds files:

An absolute path is a path that starts with your computer's root directory, for example 'C:\Python\scripts..' if you're on Windows.

A relative path is a path that does not start with your computer's root directory, and is instead relative to something called the working directory. You can view Python's current working directory by calling os.getcwd().

Other common mistakes that could cause a "file or directory not found" error include:

  • You may be using escape sequences in a file path:

        path = 'C:\Users\apps'
    
        Incorrect! The '\n' in 'Users\apps' is a line break character!
    

To avoid making this mistake, you can use any one of the below methods:

  • use raw string literals

       path = r'C:\Users\apps'
    
  • you can always use this:

     'C:/Users/apps'
    
  • another possibility is:

    'C:\\Users\\apps
    



回答2:


if it keeps answering something like this

Try to uninstall and reinstall Anaconda, but now checking the box below



来源:https://stackoverflow.com/questions/62034948/how-to-fix-ioerror-errno-2-no-such-file-or-directory-when-making-virtual-en

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!